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

+11 -3
View File
@@ -9,7 +9,8 @@ from pysmartthings import Attribute, Capability
from homeassistant.components.smartthings import switch
from homeassistant.components.smartthings.const import (
DOMAIN, SIGNAL_SMARTTHINGS_UPDATE)
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
from homeassistant.components.switch import (
ATTR_CURRENT_POWER_W, ATTR_TODAY_ENERGY_KWH, DOMAIN as SWITCH_DOMAIN)
from homeassistant.helpers.dispatcher import async_dispatcher_send
from .conftest import setup_platform
@@ -61,8 +62,13 @@ async def test_turn_off(hass, device_factory):
async def test_turn_on(hass, device_factory):
"""Test the switch turns of successfully."""
# Arrange
device = device_factory('Switch_1', [Capability.switch],
{Attribute.switch: 'off'})
device = device_factory('Switch_1',
[Capability.switch,
Capability.power_meter,
Capability.energy_meter],
{Attribute.switch: 'off',
Attribute.power: 355,
Attribute.energy: 11.422})
await setup_platform(hass, SWITCH_DOMAIN, device)
# Act
await hass.services.async_call(
@@ -72,6 +78,8 @@ async def test_turn_on(hass, device_factory):
state = hass.states.get('switch.switch_1')
assert state is not None
assert state.state == 'on'
assert state.attributes[ATTR_CURRENT_POWER_W] == 355
assert state.attributes[ATTR_TODAY_ENERGY_KWH] == 11.422
async def test_update_from_signal(hass, device_factory):