From 9e386938bb1e4b8bc90ba32fb5ce7c345dc8182b Mon Sep 17 00:00:00 2001 From: Matt Schmitt Date: Mon, 8 Oct 2018 08:19:23 -0400 Subject: [PATCH] MyQ cover return unknown state if not available (#17207) * Add additional supported states * Use get method for lookup * Return None if unable to get status --- homeassistant/components/cover/myq.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/cover/myq.py b/homeassistant/components/cover/myq.py index 78b6f891f11..5ceb4260d0c 100644 --- a/homeassistant/components/cover/myq.py +++ b/homeassistant/components/cover/myq.py @@ -11,8 +11,8 @@ import voluptuous as vol from homeassistant.components.cover import ( CoverDevice, SUPPORT_CLOSE, SUPPORT_OPEN) from homeassistant.const import ( - CONF_PASSWORD, CONF_TYPE, CONF_USERNAME, STATE_CLOSED, STATE_OPEN, - STATE_CLOSING, STATE_OPENING) + CONF_PASSWORD, CONF_TYPE, CONF_USERNAME, STATE_CLOSED, STATE_CLOSING, + STATE_OPEN, STATE_OPENING) import homeassistant.helpers.config_validation as cv REQUIREMENTS = ['pymyq==0.0.15'] @@ -23,8 +23,8 @@ DEFAULT_NAME = 'myq' MYQ_TO_HASS = { 'closed': STATE_CLOSED, - 'open': STATE_OPEN, 'closing': STATE_CLOSING, + 'open': STATE_OPEN, 'opening': STATE_OPENING } @@ -76,7 +76,7 @@ class MyQDevice(CoverDevice): self.myq = myq self.device_id = device['deviceid'] self._name = device['name'] - self._status = STATE_CLOSED + self._status = None @property def device_class(self): @@ -96,17 +96,19 @@ class MyQDevice(CoverDevice): @property def is_closed(self): """Return true if cover is closed, else False.""" - return MYQ_TO_HASS[self._status] == STATE_CLOSED + if self._status in [None, False]: + return None + return MYQ_TO_HASS.get(self._status) == STATE_CLOSED @property def is_closing(self): """Return if the cover is closing or not.""" - return MYQ_TO_HASS[self._status] == STATE_CLOSING + return MYQ_TO_HASS.get(self._status) == STATE_CLOSING @property def is_opening(self): """Return if the cover is opening or not.""" - return MYQ_TO_HASS[self._status] == STATE_OPENING + return MYQ_TO_HASS.get(self._status) == STATE_OPENING def close_cover(self, **kwargs): """Issue close command to cover."""