mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 01:38:02 +00:00
Merge pull request #6001 from jumpkick/patch-2
Improvements for WeMo Insight switches
This commit is contained in:
commit
11c4d3892f
@ -5,6 +5,7 @@ For more details about this component, please refer to the documentation at
|
|||||||
https://home-assistant.io/components/switch.wemo/
|
https://home-assistant.io/components/switch.wemo/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from homeassistant.components.switch import SwitchDevice
|
from homeassistant.components.switch import SwitchDevice
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -110,11 +111,30 @@ class WemoSwitch(SwitchDevice):
|
|||||||
if self.insight_params or (self.coffeemaker_mode is not None):
|
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.insight_params:
|
||||||
|
attr['on_latest_time'] = \
|
||||||
|
WemoSwitch.as_uptime(self.insight_params['onfor'])
|
||||||
|
attr['on_today_time'] = \
|
||||||
|
WemoSwitch.as_uptime(self.insight_params['ontoday'])
|
||||||
|
attr['on_total_time'] = \
|
||||||
|
WemoSwitch.as_uptime(self.insight_params['ontotal'])
|
||||||
|
attr['power_threshold_mw'] = \
|
||||||
|
self.insight_params['powerthreshold']
|
||||||
|
|
||||||
if self.coffeemaker_mode is not None:
|
if self.coffeemaker_mode is not None:
|
||||||
attr[ATTR_COFFEMAKER_MODE] = self.coffeemaker_mode
|
attr[ATTR_COFFEMAKER_MODE] = self.coffeemaker_mode
|
||||||
|
|
||||||
return attr
|
return attr
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def as_uptime(_seconds):
|
||||||
|
"""Format seconds into uptime string in the format: 00d 00h 00m 00s."""
|
||||||
|
uptime = datetime(1, 1, 1) + timedelta(seconds=_seconds)
|
||||||
|
return "{:0>2d}d {:0>2d}h {:0>2d}m {:0>2d}s".format(uptime.day-1,
|
||||||
|
uptime.hour,
|
||||||
|
uptime.minute,
|
||||||
|
uptime.second)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_power_mwh(self):
|
def current_power_mwh(self):
|
||||||
"""Current power usage in mWh."""
|
"""Current power usage in mWh."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user