Add standby state to WeMo Insight Switch, and add WeMo Maker
parent
c1b6d03d1b
commit
dfae1a44a6
|
@ -24,6 +24,8 @@ ENTITY_ID_FORMAT = DOMAIN + '.{}'
|
|||
|
||||
ATTR_TODAY_MWH = "today_mwh"
|
||||
ATTR_CURRENT_POWER_MWH = "current_power_mwh"
|
||||
ATTR_STANDBY_STATE = "standby_state"
|
||||
ATTR_SENSOR_STATE = "sensor_state"
|
||||
|
||||
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
||||
|
||||
|
@ -37,6 +39,8 @@ DISCOVERY_PLATFORMS = {
|
|||
PROP_TO_ATTR = {
|
||||
'current_power_mwh': ATTR_CURRENT_POWER_MWH,
|
||||
'today_power_mw': ATTR_TODAY_MWH,
|
||||
'standby_state': ATTR_STANDBY_STATE,
|
||||
'sensor_state': ATTR_SENSOR_STATE
|
||||
}
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -45,21 +49,18 @@ _LOGGER = logging.getLogger(__name__)
|
|||
def is_on(hass, entity_id=None):
|
||||
""" Returns if the switch is on based on the statemachine. """
|
||||
entity_id = entity_id or ENTITY_ID_ALL_SWITCHES
|
||||
|
||||
return hass.states.is_state(entity_id, STATE_ON)
|
||||
|
||||
|
||||
def turn_on(hass, entity_id=None):
|
||||
""" Turns all or specified switch on. """
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||
|
||||
hass.services.call(DOMAIN, SERVICE_TURN_ON, data)
|
||||
|
||||
|
||||
def turn_off(hass, entity_id=None):
|
||||
""" Turns all or specified switch off. """
|
||||
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
|
||||
|
||||
hass.services.call(DOMAIN, SERVICE_TURN_OFF, data)
|
||||
|
||||
|
||||
|
@ -84,7 +85,6 @@ def setup(hass, config):
|
|||
switch.update_ha_state(True)
|
||||
|
||||
hass.services.register(DOMAIN, SERVICE_TURN_OFF, handle_switch_service)
|
||||
|
||||
hass.services.register(DOMAIN, SERVICE_TURN_ON, handle_switch_service)
|
||||
|
||||
return True
|
||||
|
|
|
@ -37,6 +37,7 @@ class WemoSwitch(SwitchDevice):
|
|||
def __init__(self, wemo):
|
||||
self.wemo = wemo
|
||||
self.insight_params = None
|
||||
self.maker_params = None
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
|
@ -60,6 +61,34 @@ class WemoSwitch(SwitchDevice):
|
|||
if self.insight_params:
|
||||
return self.insight_params['todaymw']
|
||||
|
||||
@property
|
||||
def standby_state(self):
|
||||
""" Is the device on - or in standby. """
|
||||
if self.insight_params:
|
||||
return self.insight_params['standby_state']
|
||||
|
||||
@property
|
||||
def sensor_state(self):
|
||||
""" Is the sensor on or off. """
|
||||
if self.maker_params and self.has_sensor:
|
||||
# Note a state of 1 matches the WeMo app 'not triggered'!
|
||||
if self.maker_params['sensorstate']:
|
||||
return 'off'
|
||||
else:
|
||||
return 'on'
|
||||
|
||||
@property
|
||||
def switch_mode(self):
|
||||
""" Is the switch configured as toggle(0) or momentary (1). """
|
||||
if self.maker_params:
|
||||
return self.maker_params['switchmode']
|
||||
|
||||
@property
|
||||
def has_sensor(self):
|
||||
""" Is the sensor present? """
|
||||
if self.maker_params:
|
||||
return self.maker_params['hassensor']
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
""" True if switch is on. """
|
||||
|
@ -76,5 +105,8 @@ class WemoSwitch(SwitchDevice):
|
|||
def update(self):
|
||||
""" Update WeMo state. """
|
||||
self.wemo.get_state(True)
|
||||
if self.wemo.model.startswith('Belkin Insight'):
|
||||
if self.wemo.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':
|
||||
self.maker_params = self.wemo.maker_params
|
||||
|
|
Loading…
Reference in New Issue