mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Merge pull request #296 from pavoni/feature/enhance_wemo
Feature/enhance wemo
This commit is contained in:
commit
74303e4be8
@ -24,6 +24,7 @@ ENTITY_ID_FORMAT = DOMAIN + '.{}'
|
|||||||
|
|
||||||
ATTR_TODAY_MWH = "today_mwh"
|
ATTR_TODAY_MWH = "today_mwh"
|
||||||
ATTR_CURRENT_POWER_MWH = "current_power_mwh"
|
ATTR_CURRENT_POWER_MWH = "current_power_mwh"
|
||||||
|
ATTR_SENSOR_STATE = "sensor_state"
|
||||||
|
|
||||||
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
||||||
|
|
||||||
@ -38,6 +39,7 @@ DISCOVERY_PLATFORMS = {
|
|||||||
PROP_TO_ATTR = {
|
PROP_TO_ATTR = {
|
||||||
'current_power_mwh': ATTR_CURRENT_POWER_MWH,
|
'current_power_mwh': ATTR_CURRENT_POWER_MWH,
|
||||||
'today_power_mw': ATTR_TODAY_MWH,
|
'today_power_mw': ATTR_TODAY_MWH,
|
||||||
|
'sensor_state': ATTR_SENSOR_STATE
|
||||||
}
|
}
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -101,6 +103,16 @@ class SwitchDevice(ToggleEntity):
|
|||||||
""" Today total power usage in mw. """
|
""" Today total power usage in mw. """
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_standby(self):
|
||||||
|
""" Is the device in standby. """
|
||||||
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def sensor_state(self):
|
||||||
|
""" Is the sensor on or off. """
|
||||||
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
""" Returns device specific state attributes. """
|
""" Returns device specific state attributes. """
|
||||||
|
@ -7,8 +7,9 @@ Support for WeMo switches.
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.switch import SwitchDevice
|
from homeassistant.components.switch import SwitchDevice
|
||||||
|
from homeassistant.const import STATE_ON, STATE_OFF, STATE_STANDBY
|
||||||
|
|
||||||
REQUIREMENTS = ['pywemo==0.2']
|
REQUIREMENTS = ['pywemo==0.3']
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
@ -39,6 +40,7 @@ class WemoSwitch(SwitchDevice):
|
|||||||
def __init__(self, wemo):
|
def __init__(self, wemo):
|
||||||
self.wemo = wemo
|
self.wemo = wemo
|
||||||
self.insight_params = None
|
self.insight_params = None
|
||||||
|
self.maker_params = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
@ -50,6 +52,16 @@ class WemoSwitch(SwitchDevice):
|
|||||||
""" Returns the name of the switch if any. """
|
""" Returns the name of the switch if any. """
|
||||||
return self.wemo.name
|
return self.wemo.name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def state(self):
|
||||||
|
""" Returns the state. """
|
||||||
|
is_on = self.is_on
|
||||||
|
if not is_on:
|
||||||
|
return STATE_OFF
|
||||||
|
elif self.is_standby:
|
||||||
|
return STATE_STANDBY
|
||||||
|
return STATE_ON
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_power_mwh(self):
|
def current_power_mwh(self):
|
||||||
""" Current power usage in mwh. """
|
""" Current power usage in mwh. """
|
||||||
@ -62,6 +74,40 @@ class WemoSwitch(SwitchDevice):
|
|||||||
if self.insight_params:
|
if self.insight_params:
|
||||||
return self.insight_params['todaymw']
|
return self.insight_params['todaymw']
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_standby(self):
|
||||||
|
""" Is the device on - or in standby. """
|
||||||
|
if self.insight_params:
|
||||||
|
standby_state = self.insight_params['state']
|
||||||
|
# Standby is actually '8' but seems more defensive
|
||||||
|
# to check for the On and Off states
|
||||||
|
if standby_state == '1' or standby_state == '0':
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
@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 STATE_OFF
|
||||||
|
else:
|
||||||
|
return STATE_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
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
""" True if switch is on. """
|
""" True if switch is on. """
|
||||||
@ -78,5 +124,8 @@ class WemoSwitch(SwitchDevice):
|
|||||||
def update(self):
|
def update(self):
|
||||||
""" Update WeMo state. """
|
""" Update WeMo state. """
|
||||||
self.wemo.get_state(True)
|
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 = 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
|
||||||
|
@ -46,6 +46,7 @@ STATE_CLOSED = 'closed'
|
|||||||
STATE_PLAYING = 'playing'
|
STATE_PLAYING = 'playing'
|
||||||
STATE_PAUSED = 'paused'
|
STATE_PAUSED = 'paused'
|
||||||
STATE_IDLE = 'idle'
|
STATE_IDLE = 'idle'
|
||||||
|
STATE_STANDBY = 'standby'
|
||||||
|
|
||||||
# #### STATE AND EVENT ATTRIBUTES ####
|
# #### STATE AND EVENT ATTRIBUTES ####
|
||||||
# Contains current time for a TIME_CHANGED event
|
# Contains current time for a TIME_CHANGED event
|
||||||
|
@ -89,7 +89,7 @@ pynetgear==0.3
|
|||||||
netdisco==0.3
|
netdisco==0.3
|
||||||
|
|
||||||
# Wemo (switch.wemo)
|
# Wemo (switch.wemo)
|
||||||
pywemo==0.2
|
pywemo==0.3
|
||||||
|
|
||||||
# Wink (*.wink)
|
# Wink (*.wink)
|
||||||
https://github.com/balloob/python-wink/archive/c2b700e8ca866159566ecf5e644d9c297f69f257.zip
|
https://github.com/balloob/python-wink/archive/c2b700e8ca866159566ecf5e644d9c297f69f257.zip
|
||||||
|
Loading…
x
Reference in New Issue
Block a user