Revise power and energy units and property names. (#6212)
* Revise power and energy units and property names. * Add change for new wemo parameter.
This commit is contained in:
parent
970bde9e99
commit
acf75b5253
12 changed files with 50 additions and 49 deletions
|
@ -85,11 +85,11 @@ class VeraThermostat(VeraDevice, ClimateDevice):
|
||||||
return self.vera_device.fan_cycle()
|
return self.vera_device.fan_cycle()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_power_mwh(self):
|
def current_power_w(self):
|
||||||
"""Current power usage in mWh."""
|
"""Current power usage in W."""
|
||||||
power = self.vera_device.power
|
power = self.vera_device.power
|
||||||
if power:
|
if power:
|
||||||
return convert(power, float, 0.0) * 1000
|
return convert(power, float, 0.0)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Called by the vera device callback to update state."""
|
"""Called by the vera device callback to update state."""
|
||||||
|
|
|
@ -30,14 +30,14 @@ ENTITY_ID_ALL_SWITCHES = group.ENTITY_ID_FORMAT.format('all_switches')
|
||||||
|
|
||||||
ENTITY_ID_FORMAT = DOMAIN + '.{}'
|
ENTITY_ID_FORMAT = DOMAIN + '.{}'
|
||||||
|
|
||||||
ATTR_TODAY_MWH = "today_mwh"
|
ATTR_TODAY_ENERGY_KWH = "today_energy_kwh"
|
||||||
ATTR_CURRENT_POWER_MWH = "current_power_mwh"
|
ATTR_CURRRENT_POWER_W = "current_power_w"
|
||||||
|
|
||||||
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
||||||
|
|
||||||
PROP_TO_ATTR = {
|
PROP_TO_ATTR = {
|
||||||
'current_power_mwh': ATTR_CURRENT_POWER_MWH,
|
'current_power_w': ATTR_CURRRENT_POWER_W,
|
||||||
'today_power_mw': ATTR_TODAY_MWH,
|
'today_energy_kwh': ATTR_TODAY_ENERGY_KWH,
|
||||||
}
|
}
|
||||||
|
|
||||||
SWITCH_SERVICE_SCHEMA = vol.Schema({
|
SWITCH_SERVICE_SCHEMA = vol.Schema({
|
||||||
|
@ -144,13 +144,13 @@ class SwitchDevice(ToggleEntity):
|
||||||
|
|
||||||
# pylint: disable=no-self-use
|
# pylint: disable=no-self-use
|
||||||
@property
|
@property
|
||||||
def current_power_mwh(self):
|
def current_power_w(self):
|
||||||
"""Return the current power usage in mWh."""
|
"""Return the current power usage in W."""
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def today_power_mw(self):
|
def today_energy_kwh(self):
|
||||||
"""Return the today total power usage in mW."""
|
"""Return the today total energy usage in kWh."""
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -48,15 +48,15 @@ class DemoSwitch(SwitchDevice):
|
||||||
return self._assumed
|
return self._assumed
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_power_mwh(self):
|
def current_power_w(self):
|
||||||
"""Return the current power usage in mWh."""
|
"""Return the current power usage in W."""
|
||||||
if self._state:
|
if self._state:
|
||||||
return 100
|
return 100
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def today_power_mw(self):
|
def today_energy_kwh(self):
|
||||||
"""Return the today total power usage in mW."""
|
"""Return the today total energy usage in kWh."""
|
||||||
return 1500
|
return 15
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
|
|
|
@ -59,13 +59,13 @@ class SmartPlugSwitch(SwitchDevice):
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_power_mwh(self):
|
def current_power_w(self):
|
||||||
"""Return the current power usage in mWh."""
|
"""Return the current power usage in W."""
|
||||||
return self._now_power
|
return self._now_power
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def today_power_mw(self):
|
def today_energy_kwh(self):
|
||||||
"""Return the today total power usage in mW."""
|
"""Return the today total energy usage in kWh."""
|
||||||
return self._now_energy_day
|
return self._now_energy_day
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -40,8 +40,8 @@ class HMSwitch(HMDevice, SwitchDevice):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_power_mwh(self):
|
def today_energy_kwh(self):
|
||||||
"""Return the current power usage in mWh."""
|
"""Return the current power usage in kWh."""
|
||||||
if "ENERGY_COUNTER" in self._data:
|
if "ENERGY_COUNTER" in self._data:
|
||||||
try:
|
try:
|
||||||
return self._data["ENERGY_COUNTER"] / 1000
|
return self._data["ENERGY_COUNTER"] / 1000
|
||||||
|
|
|
@ -111,9 +111,9 @@ class MfiSwitch(SwitchDevice):
|
||||||
self._target_state = False
|
self._target_state = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_power_mwh(self):
|
def current_power_w(self):
|
||||||
"""Return the current power usage in mWh."""
|
"""Return the current power usage in W."""
|
||||||
return int(self._port.data.get('active_pwr', 0) * 1000)
|
return int(self._port.data.get('active_pwr', 0))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
|
|
|
@ -64,8 +64,8 @@ class MyStromSwitch(SwitchDevice):
|
||||||
return bool(self.data['relay'])
|
return bool(self.data['relay'])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_power_mwh(self):
|
def current_power_w(self):
|
||||||
"""Return the current power consumption in mWh."""
|
"""Return the current power consumption in W."""
|
||||||
return round(self.data['power'], 2)
|
return round(self.data['power'], 2)
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
def turn_on(self, **kwargs):
|
||||||
|
|
|
@ -23,10 +23,7 @@ REQUIREMENTS = ['pynetio==0.1.6']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
ATTR_CURRENT_POWER_MWH = 'current_power_mwh'
|
|
||||||
ATTR_CURRENT_POWER_W = 'current_power_w'
|
|
||||||
ATTR_START_DATE = 'start_date'
|
ATTR_START_DATE = 'start_date'
|
||||||
ATTR_TODAY_MWH = 'today_mwh'
|
|
||||||
ATTR_TOTAL_CONSUMPTION_KWH = 'total_energy_kwh'
|
ATTR_TOTAL_CONSUMPTION_KWH = 'total_energy_kwh'
|
||||||
|
|
||||||
CONF_OUTLETS = 'outlets'
|
CONF_OUTLETS = 'outlets'
|
||||||
|
@ -172,7 +169,6 @@ class NetioSwitch(SwitchDevice):
|
||||||
def state_attributes(self):
|
def state_attributes(self):
|
||||||
"""Return optional state attributes."""
|
"""Return optional state attributes."""
|
||||||
return {
|
return {
|
||||||
ATTR_CURRENT_POWER_W: self.current_power_w,
|
|
||||||
ATTR_TOTAL_CONSUMPTION_KWH: self.cumulated_consumption_kwh,
|
ATTR_TOTAL_CONSUMPTION_KWH: self.cumulated_consumption_kwh,
|
||||||
ATTR_START_DATE: self.start_date.split('|')[0]
|
ATTR_START_DATE: self.start_date.split('|')[0]
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,11 +46,11 @@ class VeraSwitch(VeraDevice, SwitchDevice):
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_power_mwh(self):
|
def current_power_w(self):
|
||||||
"""Current power usage in mWh."""
|
"""Current power usage in W."""
|
||||||
power = self.vera_device.power
|
power = self.vera_device.power
|
||||||
if power:
|
if power:
|
||||||
return convert(power, float, 0.0) * 1000
|
return convert(power, float, 0.0)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
|
|
|
@ -8,6 +8,7 @@ import logging
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from homeassistant.components.switch import SwitchDevice
|
from homeassistant.components.switch import SwitchDevice
|
||||||
|
from homeassistant.util import convert
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
STATE_OFF, STATE_ON, STATE_STANDBY, STATE_UNKNOWN)
|
STATE_OFF, STATE_ON, STATE_STANDBY, STATE_UNKNOWN)
|
||||||
from homeassistant.loader import get_component
|
from homeassistant.loader import get_component
|
||||||
|
@ -118,8 +119,10 @@ class WemoSwitch(SwitchDevice):
|
||||||
WemoSwitch.as_uptime(self.insight_params['ontoday'])
|
WemoSwitch.as_uptime(self.insight_params['ontoday'])
|
||||||
attr['on_total_time'] = \
|
attr['on_total_time'] = \
|
||||||
WemoSwitch.as_uptime(self.insight_params['ontotal'])
|
WemoSwitch.as_uptime(self.insight_params['ontotal'])
|
||||||
attr['power_threshold_mw'] = \
|
attr['power_threshold_w'] = \
|
||||||
self.insight_params['powerthreshold']
|
convert(
|
||||||
|
self.insight_params['powerthreshold'], float, 0.0
|
||||||
|
) / 1000.0
|
||||||
|
|
||||||
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
|
||||||
|
@ -136,16 +139,18 @@ class WemoSwitch(SwitchDevice):
|
||||||
uptime.second)
|
uptime.second)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_power_mwh(self):
|
def current_power_w(self):
|
||||||
"""Current power usage in mWh."""
|
"""Current power usage in W."""
|
||||||
if self.insight_params:
|
if self.insight_params:
|
||||||
return self.insight_params['currentpower']
|
return convert(
|
||||||
|
self.insight_params['currentpower'], float, 0.0
|
||||||
|
) / 1000.0
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def today_power_mw(self):
|
def today_energy_kwh(self):
|
||||||
"""Today total power usage in mW."""
|
"""Today total energy usage in kWh."""
|
||||||
if self.insight_params:
|
if self.insight_params:
|
||||||
return self.insight_params['todaymw']
|
return convert(self.insight_params['todaymw'], float, 0.0) / 1000.0
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def detail_state(self):
|
def detail_state(self):
|
||||||
|
|
|
@ -34,7 +34,7 @@ CONF_LIGHTS = 'lights'
|
||||||
|
|
||||||
VERA_ID_FORMAT = '{}_{}'
|
VERA_ID_FORMAT = '{}_{}'
|
||||||
|
|
||||||
ATTR_CURRENT_POWER_MWH = "current_power_mwh"
|
ATTR_CURRENT_POWER_W = "current_power_w"
|
||||||
|
|
||||||
VERA_DEVICES = defaultdict(list)
|
VERA_DEVICES = defaultdict(list)
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ class VeraDevice(Entity):
|
||||||
|
|
||||||
power = self.vera_device.power
|
power = self.vera_device.power
|
||||||
if power:
|
if power:
|
||||||
attr[ATTR_CURRENT_POWER_MWH] = convert(power, float, 0.0) * 1000
|
attr[ATTR_CURRENT_POWER_W] = convert(power, float, 0.0)
|
||||||
|
|
||||||
attr['Vera Device Id'] = self.vera_device.vera_device_id
|
attr['Vera Device Id'] = self.vera_device.vera_device_id
|
||||||
|
|
||||||
|
|
|
@ -94,15 +94,15 @@ class TestMfiSwitch(unittest.TestCase):
|
||||||
self.assertEqual(self.port.control.call_args, mock.call(False))
|
self.assertEqual(self.port.control.call_args, mock.call(False))
|
||||||
self.assertFalse(self.switch._target_state)
|
self.assertFalse(self.switch._target_state)
|
||||||
|
|
||||||
def test_current_power_mwh(self):
|
def test_current_power_w(self):
|
||||||
"""Test current power."""
|
"""Test current power."""
|
||||||
self.port.data = {'active_pwr': 1}
|
self.port.data = {'active_pwr': 10}
|
||||||
self.assertEqual(1000, self.switch.current_power_mwh)
|
self.assertEqual(10, self.switch.current_power_w)
|
||||||
|
|
||||||
def test_current_power_mwh_no_data(self):
|
def test_current_power_w_no_data(self):
|
||||||
"""Test current power if there is no data."""
|
"""Test current power if there is no data."""
|
||||||
self.port.data = {'notpower': 123}
|
self.port.data = {'notpower': 123}
|
||||||
self.assertEqual(0, self.switch.current_power_mwh)
|
self.assertEqual(0, self.switch.current_power_w)
|
||||||
|
|
||||||
def test_device_state_attributes(self):
|
def test_device_state_attributes(self):
|
||||||
"""Test the state attributes."""
|
"""Test the state attributes."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue