Skip to content

Commit

Permalink
feat: rework sectors, fix pressures, and fix misidentification of IO …
Browse files Browse the repository at this point in the history
…9 as 8 (#30)

Co-authored-by: J. Nick Koston <[email protected]>
  • Loading branch information
Lash-L and bdraco authored Jan 8, 2023
1 parent c3d379c commit 7000169
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 29 deletions.
52 changes: 41 additions & 11 deletions src/oralb_ble/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ class Models(Enum):

Pro6000 = auto()
TriumphV2 = auto()
IOSeries4 = auto()
IOSeries67 = auto()
IOSeries8 = auto()
IOSeries9 = auto()
IOSeries67 = auto()
IOSeries4 = auto()
IOSeries89 = auto()
SmartSeries4000 = auto()
SmartSeries6000 = auto()
SmartSeries7000 = auto()
Expand Down Expand Up @@ -82,12 +83,17 @@ class ModelDescription:
5: "super sensitive",
6: "tongue cleaning",
8: "settings",
9: "off",
}


DEVICE_TYPES = {
Models.Pro6000: ModelDescription("Pro 6000", SMART_SERIES_MODES),
Models.TriumphV2: ModelDescription("Triumph V2", SMART_SERIES_MODES),
Models.IOSeries4: ModelDescription(
device_type="IO Series 4",
modes=IO_SERIES_MODES,
),
Models.IOSeries67: ModelDescription(
device_type="IO Series 6/7",
modes=IO_SERIES_MODES,
Expand All @@ -100,8 +106,8 @@ class ModelDescription:
device_type="IO Series 9",
modes=IO_SERIES_MODES,
),
Models.IOSeries4: ModelDescription(
device_type="IO Series 4",
Models.IOSeries89: ModelDescription(
device_type="IO Series 8/9",
modes=IO_SERIES_MODES,
),
Models.SmartSeries4000: ModelDescription(
Expand All @@ -126,7 +132,6 @@ class ModelDescription:
),
}


STATES = {
0: "unknown",
1: "initializing",
Expand Down Expand Up @@ -154,8 +159,11 @@ class ModelDescription:
56: "power button pressed",
114: "normal",
118: "button pressed",
122: "power button pressed",
178: "high",
146: "high",
182: "button pressed",
186: "power button pressed",
192: "high",
240: "high",
242: "high",
Expand All @@ -173,14 +181,30 @@ class ModelDescription:
b'\x03"\x0c': Models.SmartSeries8000,
b"\x03!\x0b": Models.SmartSeries9000,
b"\x03!\x0c": Models.SmartSeries9000,
b"\x061\x19": Models.IOSeries8,
b"\x061\x16": Models.IOSeries9,
b"\x061\x19": Models.IOSeries89,
b"\x061\x16": Models.IOSeries89,
b"\x02\x02\x06": Models.TriumphV2,
b"\x01\x02\x05": Models.Pro6000,
}

SECTOR_MAP = {
254: "last sector",
255: "no sector",
1: "sector 1",
9: "sector 1",
2: "sector 2",
10: "sector 2",
3: "sector 3",
11: "sector 3",
19: "sector 3",
27: "sector 3",
7: "sector 4",
15: "sector 4",
31: "sector 4",
39: "sector 4",
41: "success",
42: "success",
43: "success",
47: "success",
55: "success",
}


Expand Down Expand Up @@ -225,10 +249,16 @@ def _start_update(self, service_info: BluetoothServiceInfo) -> None:
tb_state = STATES.get(state, f"unknown state {state}")
tb_mode = modes.get(mode, f"unknown mode {mode}")
tb_pressure = PRESSURE.get(pressure, f"unknown pressure {pressure}")
tb_sector = SECTOR_MAP.get(sector, f"sector {sector}")
tb_sector = SECTOR_MAP.get(sector, f"unknown sector code {sector}")

self.update_sensor(str(OralBSensor.TIME), None, time, None, "Time")
self.update_sensor(str(OralBSensor.SECTOR), None, tb_sector, None, "Sector")
if time == 0 and tb_state != "running":
# When starting up, sector is not accurate.
self.update_sensor(
str(OralBSensor.SECTOR), None, "no sector", None, "Sector"
)
else:
self.update_sensor(str(OralBSensor.SECTOR), None, tb_sector, None, "Sector")
if no_of_sectors is not None:
self.update_sensor(
str(OralBSensor.NUMBER_OF_SECTORS),
Expand Down
36 changes: 18 additions & 18 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def test_dataset_1():
DeviceKey(key="sector", device_id=None): SensorValue(
device_key=DeviceKey(key="sector", device_id=None),
name="Sector",
native_value="sector " "1",
native_value="no " "sector",
),
DeviceKey(key="number_of_sectors", device_id=None): SensorValue(
device_key=DeviceKey(key="number_of_sectors", device_id=None),
Expand Down Expand Up @@ -777,7 +777,7 @@ def test_io_series_6():
DeviceKey(key="sector", device_id=None): SensorValue(
device_key=DeviceKey(key="sector", device_id=None),
name="Sector",
native_value="sector " "1",
native_value="no " "sector",
),
DeviceKey(key="toothbrush_state", device_id=None): SensorValue(
device_key=DeviceKey(key="toothbrush_state", device_id=None),
Expand Down Expand Up @@ -892,7 +892,7 @@ def test_io_series_6_daily_clean_mode():
DeviceKey(key="sector", device_id=None): SensorValue(
device_key=DeviceKey(key="sector", device_id=None),
name="Sector",
native_value="sector " "1",
native_value="no " "sector",
),
DeviceKey(key="toothbrush_state", device_id=None): SensorValue(
device_key=DeviceKey(key="toothbrush_state", device_id=None),
Expand Down Expand Up @@ -1007,7 +1007,7 @@ def test_io_series_6_sensitive_mode():
DeviceKey(key="sector", device_id=None): SensorValue(
device_key=DeviceKey(key="sector", device_id=None),
name="Sector",
native_value="sector " "1",
native_value="no " "sector",
),
DeviceKey(key="toothbrush_state", device_id=None): SensorValue(
device_key=DeviceKey(key="toothbrush_state", device_id=None),
Expand Down Expand Up @@ -1122,7 +1122,7 @@ def test_io_series_6_gum_care_mode():
DeviceKey(key="sector", device_id=None): SensorValue(
device_key=DeviceKey(key="sector", device_id=None),
name="Sector",
native_value="sector " "1",
native_value="no " "sector",
),
DeviceKey(key="toothbrush_state", device_id=None): SensorValue(
device_key=DeviceKey(key="toothbrush_state", device_id=None),
Expand Down Expand Up @@ -1237,7 +1237,7 @@ def test_io_series_6_whiten_mode():
DeviceKey(key="sector", device_id=None): SensorValue(
device_key=DeviceKey(key="sector", device_id=None),
name="Sector",
native_value="sector " "1",
native_value="no " "sector",
),
DeviceKey(key="toothbrush_state", device_id=None): SensorValue(
device_key=DeviceKey(key="toothbrush_state", device_id=None),
Expand Down Expand Up @@ -1712,7 +1712,7 @@ def test_9000_black_series():
DeviceKey(key="sector", device_id=None): SensorValue(
device_key=DeviceKey(key="sector", device_id=None),
name="Sector",
native_value="sector " "1",
native_value="no " "sector",
),
DeviceKey(key="toothbrush_state", device_id=None): SensorValue(
device_key=DeviceKey(key="toothbrush_state", device_id=None),
Expand Down Expand Up @@ -1741,11 +1741,11 @@ def test_io_series_9():
service_info = ORALB_IO_SERIES_9
result = parser.update(service_info)
assert result == SensorUpdate(
title="IO Series 9 48BE",
title="IO Series 8/9 48BE",
devices={
None: SensorDeviceInfo(
name="IO Series 9 48BE",
model="IO Series 9",
name="IO Series 8/9 48BE",
model="IO Series 8/9",
manufacturer="Oral-B",
sw_version=None,
hw_version=None,
Expand Down Expand Up @@ -1802,7 +1802,7 @@ def test_io_series_9():
DeviceKey(key="sector", device_id=None): SensorValue(
device_key=DeviceKey(key="sector", device_id=None),
name="Sector",
native_value="sector " "2",
native_value="no " "sector",
),
DeviceKey(key="time", device_id=None): SensorValue(
device_key=DeviceKey(key="time", device_id=None),
Expand Down Expand Up @@ -2047,7 +2047,7 @@ def test_triumph_v2():
DeviceKey(key="sector", device_id=None): SensorValue(
device_key=DeviceKey(key="sector", device_id=None),
name="Sector",
native_value="sector " "15",
native_value="no " "sector",
),
DeviceKey(key="pressure", device_id=None): SensorValue(
device_key=DeviceKey(key="pressure", device_id=None),
Expand Down Expand Up @@ -2732,7 +2732,7 @@ def test_genius_8000():
DeviceKey(key="sector", device_id=None): SensorValue(
device_key=DeviceKey(key="sector", device_id=None),
name="Sector",
native_value="sector " "15",
native_value="no " "sector",
),
},
binary_entity_descriptions={
Expand Down Expand Up @@ -2837,7 +2837,7 @@ def test_genius_8000_high_pressure():
DeviceKey(key="sector", device_id=None): SensorValue(
device_key=DeviceKey(key="sector", device_id=None),
name="Sector",
native_value="sector " "4",
native_value="unknown sector code " "4",
),
DeviceKey(key="time", device_id=None): SensorValue(
device_key=DeviceKey(key="time", device_id=None),
Expand Down Expand Up @@ -2871,11 +2871,11 @@ def test_io_series_8():
service_info = ORALB_IO_SERIES_8
result = parser.update(service_info)
assert result == SensorUpdate(
title="IO Series 8 48BE",
title="IO Series 8/9 48BE",
devices={
None: SensorDeviceInfo(
name="IO Series 8 48BE",
model="IO Series 8",
name="IO Series 8/9 48BE",
model="IO Series 8/9",
manufacturer="Oral-B",
sw_version=None,
hw_version=None,
Expand Down Expand Up @@ -2947,7 +2947,7 @@ def test_io_series_8():
DeviceKey(key="sector", device_id=None): SensorValue(
device_key=DeviceKey(key="sector", device_id=None),
name="Sector",
native_value="sector " "7",
native_value="no " "sector",
),
DeviceKey(key="time", device_id=None): SensorValue(
device_key=DeviceKey(key="time", device_id=None),
Expand Down

0 comments on commit 7000169

Please sign in to comment.