Add power and energy attributes to SmartThings switch (#21375)

This commit is contained in:
Andrew Sayre authored and Martin Hjelmare committed 2019-02-25 15:50:16 +01:00
1 parent a50bcdff1a
commit 0ccbf61aea
2 files changed
+26 -4

No files matched your search

+15 -1
View File
@@ -29,7 +29,9 @@ def get_capabilities(capabilities: Sequence[str]) -> Optional[Sequence[str]]:
# Must be able to be turned on/off.
if Capability.switch in capabilities:
return [Capability.switch]
return [Capability.switch,
Capability.energy_meter,
Capability.power_meter]
return None
@@ -50,6 +52,18 @@ class SmartThingsSwitch(SmartThingsEntity, SwitchDevice):
# the entity state ahead of receiving the confirming push updates
self.async_schedule_update_ha_state()
@property
def current_power_w(self):
"""Return the current power usage in W."""
from pysmartthings import Attribute
return self._device.status.attributes[Attribute.power].value
@property
def today_energy_kwh(self):
"""Return the today total energy usage in kWh."""
from pysmartthings import Attribute
return self._device.status.attributes[Attribute.energy].value
@property
def is_on(self) -> bool:
"""Return true if light is on."""