From f0b9aa7894e19da475c1e2debcd7f5189d7b1ebe Mon Sep 17 00:00:00 2001 From: Eric Severance Date: Tue, 24 May 2022 00:53:01 -0700 Subject: [PATCH] Bump pywemo==0.8.1 (#72400) --- .../components/wemo/binary_sensor.py | 8 +++--- homeassistant/components/wemo/entity.py | 3 +-- homeassistant/components/wemo/fan.py | 2 +- homeassistant/components/wemo/light.py | 26 ++++++++++--------- homeassistant/components/wemo/manifest.json | 2 +- homeassistant/components/wemo/switch.py | 12 +++++---- homeassistant/components/wemo/wemo_device.py | 4 +-- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/wemo/conftest.py | 2 +- tests/components/wemo/test_binary_sensor.py | 6 ++--- tests/components/wemo/test_switch.py | 6 ++--- 12 files changed, 39 insertions(+), 36 deletions(-) diff --git a/homeassistant/components/wemo/binary_sensor.py b/homeassistant/components/wemo/binary_sensor.py index 3e7b159dc63..ce7dfc2fa11 100644 --- a/homeassistant/components/wemo/binary_sensor.py +++ b/homeassistant/components/wemo/binary_sensor.py @@ -1,6 +1,5 @@ """Support for WeMo binary sensors.""" import asyncio -from typing import cast from pywemo import Insight, Maker, StandbyState @@ -49,20 +48,21 @@ class MakerBinarySensor(WemoEntity, BinarySensorEntity): """Maker device's sensor port.""" _name_suffix = "Sensor" + wemo: Maker @property def is_on(self) -> bool: """Return true if the Maker's sensor is pulled low.""" - return cast(int, self.wemo.has_sensor) != 0 and self.wemo.sensor_state == 0 + return self.wemo.has_sensor != 0 and self.wemo.sensor_state == 0 class InsightBinarySensor(WemoBinarySensor): """Sensor representing the device connected to the Insight Switch.""" _name_suffix = "Device" + wemo: Insight @property def is_on(self) -> bool: """Return true device connected to the Insight Switch is on.""" - # Note: wemo.get_standby_state is a @property. - return super().is_on and self.wemo.get_standby_state == StandbyState.ON + return super().is_on and self.wemo.standby_state == StandbyState.ON diff --git a/homeassistant/components/wemo/entity.py b/homeassistant/components/wemo/entity.py index 6d94e203932..c8ed9cdde08 100644 --- a/homeassistant/components/wemo/entity.py +++ b/homeassistant/components/wemo/entity.py @@ -4,7 +4,6 @@ from __future__ import annotations from collections.abc import Generator import contextlib import logging -from typing import cast from pywemo.exceptions import ActionException @@ -89,4 +88,4 @@ class WemoBinaryStateEntity(WemoEntity): @property def is_on(self) -> bool: """Return true if the state is on.""" - return cast(int, self.wemo.get_state()) != 0 + return self.wemo.get_state() != 0 diff --git a/homeassistant/components/wemo/fan.py b/homeassistant/components/wemo/fan.py index d62a7a3b7e3..d24827bee96 100644 --- a/homeassistant/components/wemo/fan.py +++ b/homeassistant/components/wemo/fan.py @@ -6,7 +6,7 @@ from datetime import timedelta import math from typing import Any -from pywemo.ouimeaux_device.humidifier import DesiredHumidity, FanMode, Humidifier +from pywemo import DesiredHumidity, FanMode, Humidifier import voluptuous as vol from homeassistant.components.fan import FanEntity, FanEntityFeature diff --git a/homeassistant/components/wemo/light.py b/homeassistant/components/wemo/light.py index 87ebbd9e2c3..3ff0f115a04 100644 --- a/homeassistant/components/wemo/light.py +++ b/homeassistant/components/wemo/light.py @@ -2,9 +2,9 @@ from __future__ import annotations import asyncio -from typing import Any, Optional, cast +from typing import Any, cast -from pywemo.ouimeaux_device import bridge +from pywemo import Bridge, BridgeLight, Dimmer from homeassistant.components.light import ( ATTR_BRIGHTNESS, @@ -40,7 +40,7 @@ async def async_setup_entry( async def _discovered_wemo(coordinator: DeviceCoordinator) -> None: """Handle a discovered Wemo device.""" - if isinstance(coordinator.wemo, bridge.Bridge): + if isinstance(coordinator.wemo, Bridge): async_setup_bridge(hass, config_entry, async_add_entities, coordinator) else: async_add_entities([WemoDimmer(coordinator)]) @@ -70,7 +70,8 @@ def async_setup_bridge( """Check to see if the bridge has any new lights.""" new_lights = [] - for light_id, light in coordinator.wemo.Lights.items(): + bridge = cast(Bridge, coordinator.wemo) + for light_id, light in bridge.Lights.items(): if light_id not in known_light_ids: known_light_ids.add(light_id) new_lights.append(WemoLight(coordinator, light)) @@ -87,7 +88,7 @@ class WemoLight(WemoEntity, LightEntity): _attr_supported_features = LightEntityFeature.TRANSITION - def __init__(self, coordinator: DeviceCoordinator, light: bridge.Light) -> None: + def __init__(self, coordinator: DeviceCoordinator, light: BridgeLight) -> None: """Initialize the WeMo light.""" super().__init__(coordinator) self.light = light @@ -97,17 +98,17 @@ class WemoLight(WemoEntity, LightEntity): @property def name(self) -> str: """Return the name of the device if any.""" - return cast(str, self.light.name) + return self.light.name @property def available(self) -> bool: """Return true if the device is available.""" - return super().available and self.light.state.get("available") + return super().available and self.light.state.get("available", False) @property def unique_id(self) -> str: """Return the ID of this light.""" - return cast(str, self.light.uniqueID) + return self.light.uniqueID @property def device_info(self) -> DeviceInfo: @@ -123,17 +124,17 @@ class WemoLight(WemoEntity, LightEntity): @property def brightness(self) -> int: """Return the brightness of this light between 0..255.""" - return cast(int, self.light.state.get("level", 255)) + return self.light.state.get("level", 255) @property def xy_color(self) -> tuple[float, float] | None: """Return the xy color value [float, float].""" - return self.light.state.get("color_xy") # type:ignore[no-any-return] + return self.light.state.get("color_xy") @property def color_temp(self) -> int | None: """Return the color temperature of this light in mireds.""" - return cast(Optional[int], self.light.state.get("temperature_mireds")) + return self.light.state.get("temperature_mireds") @property def color_mode(self) -> ColorMode: @@ -166,7 +167,7 @@ class WemoLight(WemoEntity, LightEntity): @property def is_on(self) -> bool: """Return true if device is on.""" - return cast(int, self.light.state.get("onoff")) != WEMO_OFF + return self.light.state.get("onoff", WEMO_OFF) != WEMO_OFF def turn_on(self, **kwargs: Any) -> None: """Turn the light on.""" @@ -210,6 +211,7 @@ class WemoDimmer(WemoBinaryStateEntity, LightEntity): _attr_supported_color_modes = {ColorMode.BRIGHTNESS} _attr_color_mode = ColorMode.BRIGHTNESS + wemo: Dimmer @property def brightness(self) -> int: diff --git a/homeassistant/components/wemo/manifest.json b/homeassistant/components/wemo/manifest.json index d048a59d38c..40bb8161d90 100644 --- a/homeassistant/components/wemo/manifest.json +++ b/homeassistant/components/wemo/manifest.json @@ -3,7 +3,7 @@ "name": "Belkin WeMo", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/wemo", - "requirements": ["pywemo==0.7.0"], + "requirements": ["pywemo==0.8.1"], "ssdp": [ { "manufacturer": "Belkin International Inc." diff --git a/homeassistant/components/wemo/switch.py b/homeassistant/components/wemo/switch.py index c3d5bcb0462..1f9f8bce01f 100644 --- a/homeassistant/components/wemo/switch.py +++ b/homeassistant/components/wemo/switch.py @@ -3,9 +3,9 @@ from __future__ import annotations import asyncio from datetime import datetime, timedelta -from typing import Any, cast +from typing import Any -from pywemo import CoffeeMaker, Insight, Maker, StandbyState +from pywemo import CoffeeMaker, Insight, Maker, StandbyState, Switch from homeassistant.components.switch import SwitchEntity from homeassistant.config_entries import ConfigEntry @@ -58,6 +58,9 @@ async def async_setup_entry( class WemoSwitch(WemoBinaryStateEntity, SwitchEntity): """Representation of a WeMo switch.""" + # All wemo devices used with WemoSwitch are subclasses of Switch. + wemo: Switch + @property def extra_state_attributes(self) -> dict[str, Any]: """Return the state attributes of the device.""" @@ -103,10 +106,9 @@ class WemoSwitch(WemoBinaryStateEntity, SwitchEntity): def detail_state(self) -> str: """Return the state of the device.""" if isinstance(self.wemo, CoffeeMaker): - return cast(str, self.wemo.mode_string) + return self.wemo.mode_string if isinstance(self.wemo, Insight): - # Note: wemo.get_standby_state is a @property. - standby_state = self.wemo.get_standby_state + standby_state = self.wemo.standby_state if standby_state == StandbyState.ON: return STATE_ON if standby_state == StandbyState.OFF: diff --git a/homeassistant/components/wemo/wemo_device.py b/homeassistant/components/wemo/wemo_device.py index 3ca47544fd7..8f5e6864059 100644 --- a/homeassistant/components/wemo/wemo_device.py +++ b/homeassistant/components/wemo/wemo_device.py @@ -3,7 +3,7 @@ import asyncio from datetime import timedelta import logging -from pywemo import Insight, WeMoDevice +from pywemo import Insight, LongPressMixin, WeMoDevice from pywemo.exceptions import ActionException from pywemo.subscribe import EVENT_TYPE_LONG_PRESS @@ -159,7 +159,7 @@ async def async_register_device( registry.on(wemo, None, device.subscription_callback) await hass.async_add_executor_job(registry.register, wemo) - if device.supports_long_press: + if isinstance(wemo, LongPressMixin): try: await hass.async_add_executor_job(wemo.ensure_long_press_virtual_device) # Temporarily handling all exceptions for #52996 & pywemo/pywemo/issues/276 diff --git a/requirements_all.txt b/requirements_all.txt index bf4f2d556ca..b5c731367c5 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2017,7 +2017,7 @@ pyvolumio==0.1.5 pywebpush==1.9.2 # homeassistant.components.wemo -pywemo==0.7.0 +pywemo==0.8.1 # homeassistant.components.wilight pywilight==0.0.70 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index f735b555859..f862c719f50 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1337,7 +1337,7 @@ pyvolumio==0.1.5 pywebpush==1.9.2 # homeassistant.components.wemo -pywemo==0.7.0 +pywemo==0.8.1 # homeassistant.components.wilight pywilight==0.0.70 diff --git a/tests/components/wemo/conftest.py b/tests/components/wemo/conftest.py index ae900e2522f..1a5998c1f94 100644 --- a/tests/components/wemo/conftest.py +++ b/tests/components/wemo/conftest.py @@ -69,7 +69,7 @@ def create_pywemo_device(pywemo_registry, pywemo_model): device.supports_long_press.return_value = cls.supports_long_press() if issubclass(cls, pywemo.Insight): - device.get_standby_state = pywemo.StandbyState.OFF + device.standby_state = pywemo.StandbyState.OFF device.current_power_watts = MOCK_INSIGHT_CURRENT_WATTS device.today_kwh = MOCK_INSIGHT_TODAY_KWH device.threshold_power_watts = MOCK_INSIGHT_STATE_THRESHOLD_POWER diff --git a/tests/components/wemo/test_binary_sensor.py b/tests/components/wemo/test_binary_sensor.py index f26428bf32b..99a5df47e25 100644 --- a/tests/components/wemo/test_binary_sensor.py +++ b/tests/components/wemo/test_binary_sensor.py @@ -117,21 +117,21 @@ class TestInsight(EntityTestHelpers): """Verify that the binary_sensor receives state updates from the registry.""" # On state. pywemo_device.get_state.return_value = 1 - pywemo_device.get_standby_state = StandbyState.ON + pywemo_device.standby_state = StandbyState.ON pywemo_registry.callbacks[pywemo_device.name](pywemo_device, "", "") await hass.async_block_till_done() assert hass.states.get(wemo_entity.entity_id).state == STATE_ON # Standby (Off) state. pywemo_device.get_state.return_value = 1 - pywemo_device.get_standby_state = StandbyState.STANDBY + pywemo_device.standby_state = StandbyState.STANDBY pywemo_registry.callbacks[pywemo_device.name](pywemo_device, "", "") await hass.async_block_till_done() assert hass.states.get(wemo_entity.entity_id).state == STATE_OFF # Off state. pywemo_device.get_state.return_value = 0 - pywemo_device.get_standby_state = StandbyState.OFF + pywemo_device.standby_state = StandbyState.OFF pywemo_registry.callbacks[pywemo_device.name](pywemo_device, "", "") await hass.async_block_till_done() assert hass.states.get(wemo_entity.entity_id).state == STATE_OFF diff --git a/tests/components/wemo/test_switch.py b/tests/components/wemo/test_switch.py index 0c024295632..0f23aa8b8b6 100644 --- a/tests/components/wemo/test_switch.py +++ b/tests/components/wemo/test_switch.py @@ -134,19 +134,19 @@ async def test_insight_state_attributes(hass, pywemo_registry): ) # Test 'ON' state detail value. - insight.get_standby_state = pywemo.StandbyState.ON + insight.standby_state = pywemo.StandbyState.ON await async_update() attributes = hass.states.get(wemo_entity.entity_id).attributes assert attributes[ATTR_CURRENT_STATE_DETAIL] == STATE_ON # Test 'STANDBY' state detail value. - insight.get_standby_state = pywemo.StandbyState.STANDBY + insight.standby_state = pywemo.StandbyState.STANDBY await async_update() attributes = hass.states.get(wemo_entity.entity_id).attributes assert attributes[ATTR_CURRENT_STATE_DETAIL] == STATE_STANDBY # Test 'UNKNOWN' state detail value. - insight.get_standby_state = None + insight.standby_state = None await async_update() attributes = hass.states.get(wemo_entity.entity_id).attributes assert attributes[ATTR_CURRENT_STATE_DETAIL] == STATE_UNKNOWN