Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions homeassistant/components/wemo/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ def extra_state_attributes(self) -> dict[str, Any]:
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
Expand Down
6 changes: 6 additions & 0 deletions tests/components/wemo/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions tests/components/wemo/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,6 @@ def wemo_entity_suffix(self):
"""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
):
Expand Down
25 changes: 25 additions & 0 deletions tests/components/wemo/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
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,
Expand Down Expand Up @@ -147,3 +150,25 @@ async def async_update():
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