From 79445a7ccc82b994f05a11f14c38ca32badcbbaa Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Tue, 26 Mar 2019 07:43:58 +0100 Subject: [PATCH] deCONZ support Xiaomi vibration sensor (#22366) * Martin pointed out in previous PR that no ending '.' in logging * Add support for Xiaomi vibration sensor --- homeassistant/components/deconz/__init__.py | 2 +- homeassistant/components/deconz/binary_sensor.py | 10 +++++++++- homeassistant/components/deconz/gateway.py | 4 ++-- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/deconz/__init__.py b/homeassistant/components/deconz/__init__.py index 957bb569110..8bdd946e2ef 100644 --- a/homeassistant/components/deconz/__init__.py +++ b/homeassistant/components/deconz/__init__.py @@ -12,7 +12,7 @@ from .config_flow import configured_hosts from .const import DEFAULT_PORT, DOMAIN, _LOGGER from .gateway import DeconzGateway -REQUIREMENTS = ['pydeconz==53'] +REQUIREMENTS = ['pydeconz==54'] CONFIG_SCHEMA = vol.Schema({ DOMAIN: vol.Schema({ diff --git a/homeassistant/components/deconz/binary_sensor.py b/homeassistant/components/deconz/binary_sensor.py index cb68b842f4a..2b0c2037248 100644 --- a/homeassistant/components/deconz/binary_sensor.py +++ b/homeassistant/components/deconz/binary_sensor.py @@ -11,6 +11,10 @@ from .deconz_device import DeconzDevice DEPENDENCIES = ['deconz'] +ATTR_ORIENTATION = 'orientation' +ATTR_TILTANGLE = 'tiltangle' +ATTR_VIBRATIONSTRENGTH = 'vibrationstrength' + async def async_setup_platform( hass, config, async_add_entities, discovery_info=None): @@ -74,7 +78,7 @@ class DeconzBinarySensor(DeconzDevice, BinarySensorDevice): @property def device_state_attributes(self): """Return the state attributes of the sensor.""" - from pydeconz.sensor import PRESENCE + from pydeconz.sensor import PRESENCE, VIBRATION attr = {} if self._device.battery: attr[ATTR_BATTERY_LEVEL] = self._device.battery @@ -82,4 +86,8 @@ class DeconzBinarySensor(DeconzDevice, BinarySensorDevice): attr[ATTR_ON] = self._device.on if self._device.type in PRESENCE and self._device.dark is not None: attr[ATTR_DARK] = self._device.dark + elif self._device.type in VIBRATION: + attr[ATTR_ORIENTATION] = self._device.orientation + attr[ATTR_TILTANGLE] = self._device.tiltangle + attr[ATTR_VIBRATIONSTRENGTH] = self._device.vibrationstrength return attr diff --git a/homeassistant/components/deconz/gateway.py b/homeassistant/components/deconz/gateway.py index 6629d4eec14..11fb247a6f4 100644 --- a/homeassistant/components/deconz/gateway.py +++ b/homeassistant/components/deconz/gateway.py @@ -44,7 +44,7 @@ class DeconzGateway: raise ConfigEntryNotReady except Exception: # pylint: disable=broad-except - _LOGGER.error('Error connecting with deCONZ gateway.') + _LOGGER.error('Error connecting with deCONZ gateway') return False for component in SUPPORTED_PLATFORMS: @@ -135,7 +135,7 @@ async def get_gateway(hass, config, async_add_device_callback, return deconz except errors.Unauthorized: - _LOGGER.warning("Invalid key for deCONZ at %s.", config[CONF_HOST]) + _LOGGER.warning("Invalid key for deCONZ at %s", config[CONF_HOST]) raise AuthenticationRequired except (asyncio.TimeoutError, errors.RequestError): diff --git a/requirements_all.txt b/requirements_all.txt index 15db65c1608..401d22cd551 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1004,7 +1004,7 @@ pydaikin==1.2.0 pydanfossair==0.0.7 # homeassistant.components.deconz -pydeconz==53 +pydeconz==54 # homeassistant.components.zwave pydispatcher==2.0.5 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 8f88e5bb67b..17c993bf5f7 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -203,7 +203,7 @@ pyHS100==0.3.4 pyblackbird==0.5 # homeassistant.components.deconz -pydeconz==53 +pydeconz==54 # homeassistant.components.zwave pydispatcher==2.0.5