Use properties of wemo Maker device (#72378)
This commit is contained in:
parent
4baf59666a
commit
92582beeff
4 changed files with 34 additions and 16 deletions
homeassistant/components/wemo
tests/components/wemo
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
):
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue