Use properties of wemo Maker device ()

This commit is contained in:
Eric Severance 2022-05-23 10:28:16 -07:00 committed by GitHub
parent 4baf59666a
commit 92582beeff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 16 deletions
homeassistant/components/wemo
tests/components/wemo

View file

@ -64,15 +64,15 @@ class WemoSwitch(WemoBinaryStateEntity, SwitchEntity):
attr: dict[str, Any] = {}
if isinstance(self.wemo, Maker):
# Is the maker sensor on or off.
if self.wemo.maker_params["hassensor"]:
if self.wemo.has_sensor:
# Note a state of 1 matches the WeMo app 'not triggered'!
if self.wemo.maker_params["sensorstate"]:
if self.wemo.sensor_state:
attr[ATTR_SENSOR_STATE] = STATE_OFF
else:
attr[ATTR_SENSOR_STATE] = STATE_ON
# Is the maker switch configured as toggle(0) or momentary (1).
if self.wemo.maker_params["switchmode"]:
if self.wemo.switch_mode:
attr[ATTR_SWITCH_MODE] = MAKER_SWITCH_MOMENTARY
else:
attr[ATTR_SWITCH_MODE] = MAKER_SWITCH_TOGGLE

View file

@ -77,6 +77,12 @@ def create_pywemo_device(pywemo_registry, pywemo_model):
device.today_on_time = 5678
device.total_on_time = 9012
if issubclass(cls, pywemo.Maker):
device.has_sensor = 1
device.sensor_state = 1
device.switch_mode = 1
device.switch_state = 0
url = f"http://{MOCK_HOST}:{MOCK_PORT}/setup.xml"
with patch("pywemo.setup_url_for_address", return_value=url), patch(
"pywemo.discovery.device_from_description", return_value=device

View file

@ -81,19 +81,6 @@ class TestMaker(EntityTestHelpers):
"""Select the MakerBinarySensor entity."""
return MakerBinarySensor._name_suffix.lower()
@pytest.fixture(name="pywemo_device")
def pywemo_device_fixture(self, pywemo_device):
"""Fixture for WeMoDevice instances."""
pywemo_device.maker_params = {
"hassensor": 1,
"sensorstate": 1,
"switchmode": 1,
"switchstate": 0,
}
pywemo_device.has_sensor = pywemo_device.maker_params["hassensor"]
pywemo_device.sensor_state = pywemo_device.maker_params["sensorstate"]
yield pywemo_device
async def test_registry_state_callback(
self, hass, pywemo_registry, pywemo_device, wemo_entity
):

View file

@ -14,6 +14,9 @@ from homeassistant.components.wemo.switch import (
ATTR_ON_TODAY_TIME,
ATTR_ON_TOTAL_TIME,
ATTR_POWER_THRESHOLD,
ATTR_SENSOR_STATE,
ATTR_SWITCH_MODE,
MAKER_SWITCH_MOMENTARY,
)
from homeassistant.const import (
ATTR_ENTITY_ID,
@ -147,3 +150,25 @@ async def test_insight_state_attributes(hass, pywemo_registry):
await async_update()
attributes = hass.states.get(wemo_entity.entity_id).attributes
assert attributes[ATTR_CURRENT_STATE_DETAIL] == STATE_UNKNOWN
async def test_maker_state_attributes(hass, pywemo_registry):
"""Verify the switch attributes are set for the Insight device."""
await async_setup_component(hass, HA_DOMAIN, {})
with create_pywemo_device(pywemo_registry, "Maker") as maker:
wemo_entity = await async_create_wemo_entity(hass, maker, "")
attributes = hass.states.get(wemo_entity.entity_id).attributes
assert attributes[ATTR_SENSOR_STATE] == STATE_OFF
assert attributes[ATTR_SWITCH_MODE] == MAKER_SWITCH_MOMENTARY
# Test 'ON' sensor state and 'TOGGLE' switch mode values.
maker.sensor_state = 0
maker.switch_mode = 0
await hass.services.async_call(
HA_DOMAIN,
SERVICE_UPDATE_ENTITY,
{ATTR_ENTITY_ID: [wemo_entity.entity_id]},
blocking=True,
)
attributes = hass.states.get(wemo_entity.entity_id).attributes
assert attributes[ATTR_SENSOR_STATE] == STATE_ON