mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Add Support for Xiaomi Vibration Sensor (#16422)
This commit is contained in:
parent
3f498bd042
commit
71a0274b12
@ -68,6 +68,12 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
'dual_channel', hass, gateway))
|
'dual_channel', hass, gateway))
|
||||||
elif model in ['cube', 'sensor_cube', 'sensor_cube.aqgl01']:
|
elif model in ['cube', 'sensor_cube', 'sensor_cube.aqgl01']:
|
||||||
devices.append(XiaomiCube(device, hass, gateway))
|
devices.append(XiaomiCube(device, hass, gateway))
|
||||||
|
elif model in ['vibration', 'vibration.aq1']:
|
||||||
|
devices.append(XiaomiVibration(device, 'Vibration',
|
||||||
|
'status', gateway))
|
||||||
|
else:
|
||||||
|
_LOGGER.warning('Unmapped Device Model %s', model)
|
||||||
|
|
||||||
add_entities(devices)
|
add_entities(devices)
|
||||||
|
|
||||||
|
|
||||||
@ -314,6 +320,38 @@ class XiaomiSmokeSensor(XiaomiBinarySensor):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
class XiaomiVibration(XiaomiBinarySensor):
|
||||||
|
"""Representation of a Xiaomi Vibration Sensor."""
|
||||||
|
|
||||||
|
def __init__(self, device, name, data_key, xiaomi_hub):
|
||||||
|
"""Initialize the XiaomiVibration."""
|
||||||
|
self._last_action = None
|
||||||
|
super().__init__(device, name, xiaomi_hub, data_key, None)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_state_attributes(self):
|
||||||
|
"""Return the state attributes."""
|
||||||
|
attrs = {ATTR_LAST_ACTION: self._last_action}
|
||||||
|
attrs.update(super().device_state_attributes)
|
||||||
|
return attrs
|
||||||
|
|
||||||
|
def parse_data(self, data, raw_data):
|
||||||
|
"""Parse data sent by gateway."""
|
||||||
|
value = data.get(self._data_key)
|
||||||
|
if value not in ('vibrate', 'tilt', 'free_fall'):
|
||||||
|
_LOGGER.warning("Unsupported movement_type detected: %s",
|
||||||
|
value)
|
||||||
|
return False
|
||||||
|
|
||||||
|
self.hass.bus.fire('xiaomi_aqara.movement', {
|
||||||
|
'entity_id': self.entity_id,
|
||||||
|
'movement_type': value
|
||||||
|
})
|
||||||
|
self._last_action = value
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class XiaomiButton(XiaomiBinarySensor):
|
class XiaomiButton(XiaomiBinarySensor):
|
||||||
"""Representation of a Xiaomi Button."""
|
"""Representation of a Xiaomi Button."""
|
||||||
|
|
||||||
|
@ -41,6 +41,15 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
elif device['model'] in ['gateway', 'gateway.v3', 'acpartner.v3']:
|
elif device['model'] in ['gateway', 'gateway.v3', 'acpartner.v3']:
|
||||||
devices.append(XiaomiSensor(device, 'Illumination',
|
devices.append(XiaomiSensor(device, 'Illumination',
|
||||||
'illumination', gateway))
|
'illumination', gateway))
|
||||||
|
elif device['model'] in ['vibration']:
|
||||||
|
devices.append(XiaomiSensor(device, 'Bed Activity',
|
||||||
|
'bed_activity', gateway))
|
||||||
|
devices.append(XiaomiSensor(device, 'Tilt Angle',
|
||||||
|
'final_tilt_angle', gateway))
|
||||||
|
devices.append(XiaomiSensor(device, 'Coordination',
|
||||||
|
'coordination', gateway))
|
||||||
|
else:
|
||||||
|
_LOGGER.warning("Unmapped Device Model ")
|
||||||
add_entities(devices)
|
add_entities(devices)
|
||||||
|
|
||||||
|
|
||||||
@ -84,6 +93,9 @@ class XiaomiSensor(XiaomiDevice):
|
|||||||
value = data.get(self._data_key)
|
value = data.get(self._data_key)
|
||||||
if value is None:
|
if value is None:
|
||||||
return False
|
return False
|
||||||
|
if self._data_key in ['coordination', 'status']:
|
||||||
|
self._state = value
|
||||||
|
return True
|
||||||
value = float(value)
|
value = float(value)
|
||||||
if self._data_key in ['temperature', 'humidity', 'pressure']:
|
if self._data_key in ['temperature', 'humidity', 'pressure']:
|
||||||
value /= 100
|
value /= 100
|
||||||
|
Loading…
x
Reference in New Issue
Block a user