diff --git a/custom_components/ble_monitor/ble_parser/xiaomi.py b/custom_components/ble_monitor/ble_parser/xiaomi.py index 90debc2cf..f1c46d64b 100755 --- a/custom_components/ble_monitor/ble_parser/xiaomi.py +++ b/custom_components/ble_monitor/ble_parser/xiaomi.py @@ -413,10 +413,10 @@ def obj1001(xobj, device_type): elif button_type == 8: bathroom_remote_command = "heat" - # press type and dimmer + # press type and dimmer steps button_press_type = "no press" btn_switch_press_type = "no press" - dimmer = None + steps = None if press == 0: button_press_type = "single press" @@ -430,24 +430,24 @@ def obj1001(xobj, device_type): elif press == 3: if button_type == 0: button_press_type = "short press" - dimmer = value + steps = value if button_type == 1: button_press_type = "long press" - dimmer = value + steps = value elif press == 4: if button_type == 0: if value <= 127: button_press_type = "rotate right" - dimmer = value + steps = value else: button_press_type = "rotate left" - dimmer = 256 - value + steps = 256 - value elif button_type <= 127: button_press_type = "rotate right (pressed)" - dimmer = button_type + steps = button_type else: button_press_type = "rotate left (pressed)" - dimmer = 256 - button_type + steps = 256 - button_type elif press == 5: button_press_type = "short press" elif press == 6: @@ -477,8 +477,8 @@ def obj1001(xobj, device_type): result["bathroom heater remote"] = bathroom_remote_command result["button"] = button_press_type elif device_type == "YLKG07YL/YLKG08YL": - result["dimmer"] = dimmer - result["button"] = button_press_type + result["steps"] = steps + result["dimmer"] = button_press_type elif device_type == "K9B-1BTN": result["button switch"] = btn_switch_press_type result["one btn switch"] = one_btn_switch diff --git a/custom_components/ble_monitor/sensor.py b/custom_components/ble_monitor/sensor.py index b2a6a83cd..25c8d9514 100644 --- a/custom_components/ble_monitor/sensor.py +++ b/custom_components/ble_monitor/sensor.py @@ -1024,22 +1024,22 @@ class DimmerSensor(InstantUpdateSensor): def __init__(self, config, key, devtype, firmware, entity_description, manufacturer=None): """Initialize the sensor.""" super().__init__(config, key, devtype, firmware, entity_description, manufacturer) - self._button = "button" self._dimmer = self.entity_description.key + self._steps = "steps" def collect(self, data, period_cnt, batt_attr=None): """Measurements collector.""" if self.enabled is False: self.pending_update = False return - self._state = data[self._button] + " " + str(data[self._dimmer]) + " steps" + self._state = data[self._dimmer] + " " + str(data[self._steps]) + " steps" self._extra_state_attributes["last_packet_id"] = data["packet"] self._extra_state_attributes["firmware"] = data["firmware"] self._extra_state_attributes['mac_address' if self.is_beacon else 'uuid'] = dict_get_or_normalize( data, CONF_MAC, CONF_UUID ) - self._extra_state_attributes["dimmer_value"] = data[self._dimmer] - self._extra_state_attributes["last_type_of_press"] = data[self._button] + self._extra_state_attributes["dimmer_value"] = data[self._steps] + self._extra_state_attributes["last_type_of_press"] = data[self._dimmer] if batt_attr is not None: self._extra_state_attributes[ATTR_BATTERY_LEVEL] = batt_attr self.pending_update = True diff --git a/custom_components/ble_monitor/test/test_xiaomi_parser.py b/custom_components/ble_monitor/test/test_xiaomi_parser.py index f47d66cbc..a0165da5a 100644 --- a/custom_components/ble_monitor/test/test_xiaomi_parser.py +++ b/custom_components/ble_monitor/test/test_xiaomi_parser.py @@ -541,8 +541,8 @@ def test_Xiaomi_YLKG07YL_press(self): assert sensor_msg["mac"] == "F82441C5988B" assert sensor_msg["packet"] == 210 assert sensor_msg["data"] - assert sensor_msg["dimmer"] == 1 - assert sensor_msg["button"] == "short press" + assert sensor_msg["steps"] == 1 + assert sensor_msg["dimmer"] == "short press" assert sensor_msg["rssi"] == -34 def test_Xiaomi_YLKG07YL_rotate(self): @@ -568,8 +568,8 @@ def test_Xiaomi_YLKG07YL_rotate(self): assert sensor_msg["mac"] == "F82441C5988B" assert sensor_msg["packet"] == 54 assert sensor_msg["data"] - assert sensor_msg["dimmer"] == 1 - assert sensor_msg["button"] == "rotate left" + assert sensor_msg["steps"] == 1 + assert sensor_msg["dimmer"] == "rotate left" assert sensor_msg["rssi"] == -17 def test_Xiaomi_K9B(self):