mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Add support for Wemo CoffeeMaker devices (#5505)
* Add support for Wemo CoffeeMaker devices * Add CoffeeMaker to WEMO_MODEL_DISPATCH
This commit is contained in:
parent
43e46154c6
commit
191d7b0a50
@ -18,9 +18,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
ATTR_SENSOR_STATE = "sensor_state"
|
ATTR_SENSOR_STATE = "sensor_state"
|
||||||
ATTR_SWITCH_MODE = "switch_mode"
|
ATTR_SWITCH_MODE = "switch_mode"
|
||||||
ATTR_CURRENT_STATE_DETAIL = 'state_detail'
|
ATTR_CURRENT_STATE_DETAIL = 'state_detail'
|
||||||
|
ATTR_COFFEMAKER_MODE = "coffeemaker_mode"
|
||||||
MAKER_SWITCH_MOMENTARY = "momentary"
|
|
||||||
MAKER_SWITCH_TOGGLE = "toggle"
|
|
||||||
|
|
||||||
MAKER_SWITCH_MOMENTARY = "momentary"
|
MAKER_SWITCH_MOMENTARY = "momentary"
|
||||||
MAKER_SWITCH_TOGGLE = "toggle"
|
MAKER_SWITCH_TOGGLE = "toggle"
|
||||||
@ -52,7 +50,10 @@ class WemoSwitch(SwitchDevice):
|
|||||||
self.wemo = device
|
self.wemo = device
|
||||||
self.insight_params = None
|
self.insight_params = None
|
||||||
self.maker_params = None
|
self.maker_params = None
|
||||||
|
self.coffeemaker_mode = None
|
||||||
self._state = 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 = get_component('wemo')
|
||||||
wemo.SUBSCRIPTION_REGISTRY.register(self.wemo)
|
wemo.SUBSCRIPTION_REGISTRY.register(self.wemo)
|
||||||
@ -63,7 +64,11 @@ class WemoSwitch(SwitchDevice):
|
|||||||
_LOGGER.info(
|
_LOGGER.info(
|
||||||
'Subscription update for %s',
|
'Subscription update for %s',
|
||||||
_device)
|
_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'):
|
if not hasattr(self, 'hass'):
|
||||||
return
|
return
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
@ -102,9 +107,12 @@ class WemoSwitch(SwitchDevice):
|
|||||||
else:
|
else:
|
||||||
attr[ATTR_SWITCH_MODE] = MAKER_SWITCH_TOGGLE
|
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
|
attr[ATTR_CURRENT_STATE_DETAIL] = self.detail_state
|
||||||
|
|
||||||
|
if self.coffeemaker_mode is not None:
|
||||||
|
attr[ATTR_COFFEMAKER_MODE] = self.coffeemaker_mode
|
||||||
|
|
||||||
return attr
|
return attr
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -122,6 +130,8 @@ class WemoSwitch(SwitchDevice):
|
|||||||
@property
|
@property
|
||||||
def detail_state(self):
|
def detail_state(self):
|
||||||
"""Return the state of the device."""
|
"""Return the state of the device."""
|
||||||
|
if self.coffeemaker_mode is not None:
|
||||||
|
return self.wemo.mode_string
|
||||||
if self.insight_params:
|
if self.insight_params:
|
||||||
standby_state = int(self.insight_params['state'])
|
standby_state = int(self.insight_params['state'])
|
||||||
if standby_state == WEMO_ON:
|
if standby_state == WEMO_ON:
|
||||||
@ -141,12 +151,22 @@ class WemoSwitch(SwitchDevice):
|
|||||||
@property
|
@property
|
||||||
def available(self):
|
def available(self):
|
||||||
"""True if switch is available."""
|
"""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
|
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 False
|
||||||
return True
|
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):
|
def turn_on(self, **kwargs):
|
||||||
"""Turn the switch on."""
|
"""Turn the switch on."""
|
||||||
self._state = WEMO_ON
|
self._state = WEMO_ON
|
||||||
@ -161,13 +181,18 @@ class WemoSwitch(SwitchDevice):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update WeMo state."""
|
"""Update WeMo state."""
|
||||||
|
self._update(force_update=True)
|
||||||
|
|
||||||
|
def _update(self, force_update=True):
|
||||||
try:
|
try:
|
||||||
self._state = self.wemo.get_state(True)
|
self._state = self.wemo.get_state(force_update)
|
||||||
if self.wemo.model_name == 'Insight':
|
if self._model_name == 'Insight':
|
||||||
self.insight_params = self.wemo.insight_params
|
self.insight_params = self.wemo.insight_params
|
||||||
self.insight_params['standby_state'] = (
|
self.insight_params['standby_state'] = (
|
||||||
self.wemo.get_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
|
self.maker_params = self.wemo.maker_params
|
||||||
|
elif self._model_name == 'CoffeeMaker':
|
||||||
|
self.coffeemaker_mode = self.wemo.mode
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
_LOGGER.warning('Could not update status for %s', self.name)
|
_LOGGER.warning('Could not update status for %s', self.name)
|
||||||
|
@ -14,7 +14,7 @@ from homeassistant.helpers import config_validation as cv
|
|||||||
|
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||||
|
|
||||||
REQUIREMENTS = ['pywemo==0.4.9']
|
REQUIREMENTS = ['pywemo==0.4.11']
|
||||||
|
|
||||||
DOMAIN = 'wemo'
|
DOMAIN = 'wemo'
|
||||||
|
|
||||||
@ -25,7 +25,8 @@ WEMO_MODEL_DISPATCH = {
|
|||||||
'Maker': 'switch',
|
'Maker': 'switch',
|
||||||
'Sensor': 'binary_sensor',
|
'Sensor': 'binary_sensor',
|
||||||
'Socket': 'switch',
|
'Socket': 'switch',
|
||||||
'LightSwitch': 'switch'
|
'LightSwitch': 'switch',
|
||||||
|
'CoffeeMaker': 'switch'
|
||||||
}
|
}
|
||||||
|
|
||||||
SUBSCRIPTION_REGISTRY = None
|
SUBSCRIPTION_REGISTRY = None
|
||||||
|
@ -547,7 +547,7 @@ pyvera==0.2.23
|
|||||||
pywebpush==0.6.1
|
pywebpush==0.6.1
|
||||||
|
|
||||||
# homeassistant.components.wemo
|
# homeassistant.components.wemo
|
||||||
pywemo==0.4.9
|
pywemo==0.4.11
|
||||||
|
|
||||||
# homeassistant.components.light.yeelight
|
# homeassistant.components.light.yeelight
|
||||||
pyyeelight==1.0-beta
|
pyyeelight==1.0-beta
|
||||||
|
Loading…
x
Reference in New Issue
Block a user