Skip to content

Commit

Permalink
Handle extra states.
Browse files Browse the repository at this point in the history
  • Loading branch information
denpamusic committed Oct 15, 2023
1 parent 82887f5 commit 46a0356
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
20 changes: 19 additions & 1 deletion pyplumio/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,18 @@ class EncryptionType(IntEnum):
WPA2 = 4


EXTRA_STATES: Final = (
12, # STABILIZATION: ecoMAX 810P-L TOUCH
23, # STABILIZATION: ecoMAX 860P3-O
)


@unique
class DeviceState(IntEnum):
"""Contains device states."""

OFF = 0
STABILISATION = 1
STABILIZATION = 1
KINDLING = 2
WORKING = 3
SUPERVISION = 4
Expand All @@ -64,6 +70,18 @@ class DeviceState(IntEnum):
UNSEALING = 10
OTHER = 11

@classmethod
def _missing_(cls, value):
"""Look up state in extra state table.
Currently it's only used for stabilisation state,
since it differs between models.
"""
if value in EXTRA_STATES:
return cls.STABILIZATION

return None


@unique
class ProductType(IntEnum):
Expand Down
9 changes: 7 additions & 2 deletions tests/frames/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,15 @@ def test_sensor_data_decode_message(messages: dict[FrameType, bytearray]) -> Non
},
}

# Test with the unknown state.
# Test with extra state.
test_message[INDEX_STATE] = 12
frame = SensorDataMessage(message=test_message)
assert frame.data[ATTR_SENSORS][ATTR_STATE] == 12
assert frame.data[ATTR_SENSORS][ATTR_STATE] == DeviceState.STABILIZATION

# Test with the unknown state.
test_message[INDEX_STATE] = 99
frame = SensorDataMessage(message=test_message)
assert frame.data[ATTR_SENSORS][ATTR_STATE] == 99


def test_sensor_data_without_fuel_level_and_load(
Expand Down

0 comments on commit 46a0356

Please sign in to comment.