Skip to content

Commit

Permalink
Support Xiaomi Kettle sensors (no contol)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Mar 9, 2021
1 parent e452ce4 commit 692035c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
30 changes: 25 additions & 5 deletions custom_components/xiaomi_gateway3/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@

async def async_setup_entry(hass, config_entry, async_add_entities):
def setup(gateway: Gateway3, device: dict, attr: str):
async_add_entities([
Gateway3MotionSensor(gateway, device, attr)
if attr == 'motion' else
Gateway3BinarySensor(gateway, device, attr)
])
if attr == 'motion':
async_add_entities([Gateway3MotionSensor(gateway, device, attr)])
elif attr == 'power':
async_add_entities([Gateway3KettleSensor(gateway, device, attr)])
else:
async_add_entities([Gateway3BinarySensor(gateway, device, attr)])

gw: Gateway3 = hass.data[DOMAIN][config_entry.entry_id]
gw.add_setup('binary_sensor', setup)
Expand All @@ -56,6 +57,25 @@ def update(self, data: dict = None):
self.async_write_ha_state()


KETTLE = {
0: 'idle',
1: 'heat',
2: 'cool_down',
3: 'warm_up',
}


class Gateway3KettleSensor(Gateway3BinarySensor):
def update(self, data: dict = None):
if self._attr in data:
value = data[self._attr]
self._state = bool(value)
self._attrs['action_id'] = value
self._attrs['action'] = KETTLE[value]

self.async_write_ha_state()


class Gateway3MotionSensor(Gateway3BinarySensor):
_default_delay = None
_last_on = 0
Expand Down
7 changes: 6 additions & 1 deletion custom_components/xiaomi_gateway3/core/bluetooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# params: [siid, piid, hass attr name, hass domain]
DEVICES = [{
# BLE
131: ["Xiaomi", "Kettle", "YM-K1501"],
152: ["Xiaomi", "Flower Care", "HHCCJCY01"],
426: ["Xiaomi", "TH Sensor", "LYWSDCGQ/01ZM"],
794: ["Xiaomi", "Door Lock", "MJZNMS02LM"],
Expand Down Expand Up @@ -153,7 +154,7 @@
def get_ble_domain(param: str) -> Optional[str]:
if param in (
'sleep', 'lock', 'opening', 'water_leak', 'smoke', 'gas', 'light',
'contact', 'motion'):
'contact', 'motion', 'power'):
return 'binary_sensor'

elif param in (
Expand Down Expand Up @@ -194,6 +195,10 @@ def parse_xiaomi_ble(event: dict, pdid: int) -> Optional[dict]:
'temperature': int.from_bytes(data, 'little', signed=True) / 10.0
}

elif eid == 0x1005 and length == 2: # 4101
# Kettle, thanks https://github.com/custom-components/ble_monitor/
return {'power': data[0], 'temperature': data[1]}

elif eid == 0x1006 and length == 2: # 4102
# Humidity percentage, ranging from 0-1000
value = int.from_bytes(data, 'little') / 10.0
Expand Down

0 comments on commit 692035c

Please sign in to comment.