Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
528988a
UNIT and ID type changes
dlashua Dec 12, 2016
186984c
make unit a positive int
dlashua Dec 13, 2016
6acfd50
Merge branch 'dev' of https://github.com/home-assistant/home-assistan…
dlashua Sep 4, 2018
3d5690b
Support Xiaomi Vibration Sensor
dlashua Sep 4, 2018
9e36434
adding whitespace before comma
dlashua Sep 4, 2018
34b8c65
adding whitespace before comma
dlashua Sep 4, 2018
c435400
remove trailing whitespace
dlashua Sep 4, 2018
34c40eb
removed warning for unknown models
dlashua Sep 4, 2018
3b00151
readded warning so that only device output is removed
dlashua Sep 4, 2018
ad15cec
readding warning for unmapped device model
dlashua Sep 4, 2018
52b7906
used warning instead of warn
dlashua Sep 4, 2018
b0bd32a
double check that value doesn't match one of the expected values
dlashua Sep 5, 2018
e729548
Added unsupported model name to warning message
dlashua Sep 5, 2018
4183648
Don't pass in "hass" to XiaomiVibration.
dlashua Sep 5, 2018
f6933d0
be consistent with tabs and spaces
dlashua Sep 5, 2018
556bf3f
line too long for houndci-bot
dlashua Sep 5, 2018
9842eb2
clean up trailing whitespace
dlashua Sep 5, 2018
9365357
making additional changes requested.
dlashua Sep 5, 2018
e0d02a3
add more spacing to make houndci-bot happy
dlashua Sep 5, 2018
106040b
Merge branch 'dev' of https://github.com/home-assistant/home-assistan…
dlashua Sep 6, 2018
f7160b6
Merge branch 'dev' into xiaomiVibration
dlashua Sep 6, 2018
cc71ce1
Add additional model name
syssi Oct 8, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions homeassistant/components/binary_sensor/xiaomi_aqara.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
'dual_channel', hass, gateway))
elif model in ['cube', 'sensor_cube', 'sensor_cube.aqgl01']:
devices.append(XiaomiCube(device, hass, gateway))
elif model in ['vibration']:
devices.append(XiaomiVibration(device, 'Vibration',
'status', hass, gateway))
add_entities(devices)


Expand Down Expand Up @@ -311,6 +314,48 @@ def parse_data(self, data, raw_data):
return False


class XiaomiVibration(XiaomiBinarySensor):
"""Representation of a Xiaomi Vibration Sensor."""

def __init__(self, device, name, data_key, hass, xiaomi_hub):
Comment thread
dlashua marked this conversation as resolved.
Outdated
"""Initialize the XiaomiVibration."""
self._hass = hass
Comment thread
dlashua marked this conversation as resolved.
Outdated
self._last_action = None
XiaomiBinarySensor.__init__(self, device, name, xiaomi_hub,
Comment thread
dlashua marked this conversation as resolved.
Outdated
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 is None:
return False

if value == 'vibrate':
movement_type = 'vibrate'
elif value == 'tilt':
movement_type = 'tilt'
elif value == "free_fall":
movement_type = 'free_fall'
else:
_LOGGER.warning("Unsupported movement_type detected: %s", value)
return False
Comment thread
dlashua marked this conversation as resolved.

self._hass.bus.fire('movement', {
Comment thread
dlashua marked this conversation as resolved.
Outdated
'entity_id': self.entity_id,
'movement_type': movement_type
})
self._last_action = movement_type

return True

Comment thread
dlashua marked this conversation as resolved.

class XiaomiButton(XiaomiBinarySensor):
"""Representation of a Xiaomi Button."""

Expand Down
13 changes: 13 additions & 0 deletions homeassistant/components/sensor/xiaomi_aqara.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
elif device['model'] in ['gateway', 'gateway.v3', 'acpartner.v3']:
devices.append(XiaomiSensor(device, 'Illumination',
'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.warn("Unmapped Device Model ")
Comment thread
dlashua marked this conversation as resolved.
Outdated
_LOGGER.warn(device)

@Danielhiversen Danielhiversen Sep 4, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

add_entities(devices)


Expand Down Expand Up @@ -84,6 +94,9 @@ def parse_data(self, data, raw_data):
value = data.get(self._data_key)
if value is None:
return False
if self._data_key in ['coordination', 'status']:
self._state = value
return True
value = float(value)
if self._data_key in ['temperature', 'humidity', 'pressure']:
value /= 100
Expand Down