diff --git a/homeassistant/components/switch/wemo.py b/homeassistant/components/switch/wemo.py index 2d3d5ea5547..3af93d08fc8 100644 --- a/homeassistant/components/switch/wemo.py +++ b/homeassistant/components/switch/wemo.py @@ -18,9 +18,7 @@ _LOGGER = logging.getLogger(__name__) ATTR_SENSOR_STATE = "sensor_state" ATTR_SWITCH_MODE = "switch_mode" ATTR_CURRENT_STATE_DETAIL = 'state_detail' - -MAKER_SWITCH_MOMENTARY = "momentary" -MAKER_SWITCH_TOGGLE = "toggle" +ATTR_COFFEMAKER_MODE = "coffeemaker_mode" MAKER_SWITCH_MOMENTARY = "momentary" MAKER_SWITCH_TOGGLE = "toggle" @@ -52,7 +50,10 @@ class WemoSwitch(SwitchDevice): self.wemo = device self.insight_params = None self.maker_params = None + self.coffeemaker_mode = None self._state = None + # look up model name once as it incurs network traffic + self._model_name = self.wemo.model_name wemo = get_component('wemo') wemo.SUBSCRIPTION_REGISTRY.register(self.wemo) @@ -63,7 +64,11 @@ class WemoSwitch(SwitchDevice): _LOGGER.info( 'Subscription update for %s', _device) - self.update() + if self._model_name == 'CoffeeMaker': + self.wemo.subscription_callback(_params) + self._update(force_update=False) + else: + self.update() if not hasattr(self, 'hass'): return self.schedule_update_ha_state() @@ -102,9 +107,12 @@ class WemoSwitch(SwitchDevice): else: attr[ATTR_SWITCH_MODE] = MAKER_SWITCH_TOGGLE - if self.insight_params: + if self.insight_params or (self.coffeemaker_mode is not None): attr[ATTR_CURRENT_STATE_DETAIL] = self.detail_state + if self.coffeemaker_mode is not None: + attr[ATTR_COFFEMAKER_MODE] = self.coffeemaker_mode + return attr @property @@ -122,6 +130,8 @@ class WemoSwitch(SwitchDevice): @property def detail_state(self): """Return the state of the device.""" + if self.coffeemaker_mode is not None: + return self.wemo.mode_string if self.insight_params: standby_state = int(self.insight_params['state']) if standby_state == WEMO_ON: @@ -141,12 +151,22 @@ class WemoSwitch(SwitchDevice): @property def available(self): """True if switch is available.""" - if self.wemo.model_name == 'Insight' and self.insight_params is None: + if self._model_name == 'Insight' and self.insight_params is None: return False - if self.wemo.model_name == 'Maker' and self.maker_params is None: + if self._model_name == 'Maker' and self.maker_params is None: + return False + if self._model_name == 'CoffeeMaker' and self.coffeemaker_mode is None: return False return True + @property + def icon(self): + """Icon of device based on its type.""" + if self._model_name == 'CoffeeMaker': + return 'mdi:coffee' + else: + return super().icon + def turn_on(self, **kwargs): """Turn the switch on.""" self._state = WEMO_ON @@ -161,13 +181,18 @@ class WemoSwitch(SwitchDevice): def update(self): """Update WeMo state.""" + self._update(force_update=True) + + def _update(self, force_update=True): try: - self._state = self.wemo.get_state(True) - if self.wemo.model_name == 'Insight': + self._state = self.wemo.get_state(force_update) + if self._model_name == 'Insight': self.insight_params = self.wemo.insight_params self.insight_params['standby_state'] = ( self.wemo.get_standby_state) - elif self.wemo.model_name == 'Maker': + elif self._model_name == 'Maker': self.maker_params = self.wemo.maker_params + elif self._model_name == 'CoffeeMaker': + self.coffeemaker_mode = self.wemo.mode except AttributeError: _LOGGER.warning('Could not update status for %s', self.name) diff --git a/homeassistant/components/wemo.py b/homeassistant/components/wemo.py index ba068905087..3fea17ccee5 100644 --- a/homeassistant/components/wemo.py +++ b/homeassistant/components/wemo.py @@ -14,7 +14,7 @@ from homeassistant.helpers import config_validation as cv from homeassistant.const import EVENT_HOMEASSISTANT_STOP -REQUIREMENTS = ['pywemo==0.4.9'] +REQUIREMENTS = ['pywemo==0.4.11'] DOMAIN = 'wemo' @@ -25,7 +25,8 @@ WEMO_MODEL_DISPATCH = { 'Maker': 'switch', 'Sensor': 'binary_sensor', 'Socket': 'switch', - 'LightSwitch': 'switch' + 'LightSwitch': 'switch', + 'CoffeeMaker': 'switch' } SUBSCRIPTION_REGISTRY = None diff --git a/requirements_all.txt b/requirements_all.txt index e7e54ada716..6bb84a897de 100755 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -547,7 +547,7 @@ pyvera==0.2.23 pywebpush==0.6.1 # homeassistant.components.wemo -pywemo==0.4.9 +pywemo==0.4.11 # homeassistant.components.light.yeelight pyyeelight==1.0-beta