Update device_state_attributes only

This gets rid of the other stuff and just updates device_state_attributes, leaving the default properties alone.
pull/6001/head
jumpkick 2017-02-23 04:54:09 -05:00 committed by GitHub
parent f6e46aecf5
commit ef87d4dad4
1 changed files with 18 additions and 72 deletions

View File

@ -21,16 +21,6 @@ ATTR_SWITCH_MODE = "switch_mode"
ATTR_CURRENT_STATE_DETAIL = 'state_detail'
ATTR_COFFEMAKER_MODE = "coffeemaker_mode"
# Wemo Insight
ATTR_POWER_CURRENT_W = 'power_current_w'
# ATTR_POWER_AVG_W = 'power_average_w'
ATTR_POWER_TODAY_MW_MIN = 'power_today_mW_min'
ATTR_POWER_TOTAL_MW_MIN = 'power_total_mW_min'
ATTR_ON_FOR_TIME = 'on_time_most_recent'
ATTR_ON_TODAY_TIME = 'on_time_today'
ATTR_ON_TOTAL_TIME = 'on_time_total'
ATTR_POWER_THRESHOLD = 'power_threshold_w'
MAKER_SWITCH_MOMENTARY = "momentary"
MAKER_SWITCH_TOGGLE = "toggle"
@ -120,44 +110,24 @@ class WemoSwitch(SwitchDevice):
if self.insight_params or (self.coffeemaker_mode is not None):
attr[ATTR_CURRENT_STATE_DETAIL] = self.detail_state
attr[ATTR_POWER_CURRENT_W] = self.power_current_watt
# attr[ATTR_POWER_AVG_W] = self.power_average_watt
attr[ATTR_POWER_TODAY_MW_MIN] = self.power_today_mw_min
attr[ATTR_POWER_TOTAL_MW_MIN] = self.power_total_mw_min
attr[ATTR_ON_FOR_TIME] = self.on_for
attr[ATTR_ON_TODAY_TIME] = self.on_today
attr[ATTR_ON_TOTAL_TIME] = self.on_total
attr[ATTR_POWER_THRESHOLD] = self.power_threshold
attr['current_power_w'] = \
self.insight_params['currentpower'] / 1000
attr['today_power_mW_min'] = self.insight_params['todaymw']
attr['total_power_mW_min'] = self.insight_params['totalmw']
attr['on_time_most_recent'] = \
WemoSwitch.as_uptime(self.insight_params['onfor'])
attr['on_time_today'] = \
WemoSwitch.as_uptime(self.insight_params['ontoday'])
attr['on_time_total'] = \
WemoSwitch.as_uptime(self.insight_params['ontotal'])
attr['power_threshold_w'] = \
self.insight_params['powerthreshold'] / 1000
if self.coffeemaker_mode is not None:
attr[ATTR_COFFEMAKER_MODE] = self.coffeemaker_mode
return attr
# @property
def _current_power_mw(self):
"""Current power usage in mW."""
if self.insight_params:
try:
return self.insight_params['currentpower']
except KeyError:
return None
@property
def power_current_watt(self):
"""Current power usage in W."""
if self.insight_params:
try:
return self._current_power_mw() / 1000
except TypeError:
return None
@property
def power_threshold(self):
"""Threshold of W at which Insight will indicate it's load is ON."""
if self.insight_params:
return self.insight_params['powerthreshold'] / 1000
@staticmethod
def as_uptime(_seconds):
"""Format seconds into uptime string in the format: 00d 00h 00m 00s."""
@ -168,40 +138,16 @@ class WemoSwitch(SwitchDevice):
uptime.second)
@property
def on_for(self):
"""On time in seconds."""
def current_power_mwh(self):
"""Current power usage in mWh."""
if self.insight_params:
return WemoSwitch.as_uptime(self.insight_params['onfor'])
return self.insight_params['currentpower']
@property
def on_today(self):
"""On time in seconds."""
def today_power_mw(self):
"""Today total power usage in mW."""
if self.insight_params:
return WemoSwitch.as_uptime(self.insight_params['ontoday'])
@property
def on_total(self):
"""On time in seconds."""
if self.insight_params:
return WemoSwitch.as_uptime(self.insight_params['ontotal'])
@property
def power_total_mw_min(self):
"""Total of average mW per minute."""
if self.insight_params:
try:
return self.insight_params['totalmw']
except KeyError:
return None
@property
def power_today_mw_min(self):
"""Total consumption today in mW per minute."""
if self.insight_params:
try:
return self.insight_params['todaymw']
except KeyError:
return None
return self.insight_params['todaymw']
@property
def detail_state(self):