From 8f3ad48ce79442e870b27a3c52ce3e554c29c8a6 Mon Sep 17 00:00:00 2001 From: h3nrytan Date: Fri, 7 Jun 2024 09:15:00 +0800 Subject: [PATCH 1/2] Update fan.py Fix warning:- SUPPORT_SET_SPEED was used from smartir, this is a deprecated constant.. Use FanEntityFeature.SET_SPEED instead.. SUPPORT_DIRECTION was used from smartir, this is a deprecated constant.. Use FanEntityFeature.DIRECTION instead.. SUPPORT_OSCILLATE was used from smartir, this is a deprecated constant.. Use FanEntityFeature.OSCILLATE instead.. --- custom_components/smartir/fan.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/custom_components/smartir/fan.py b/custom_components/smartir/fan.py index 5b7ae4ac..2ee3a4ca 100644 --- a/custom_components/smartir/fan.py +++ b/custom_components/smartir/fan.py @@ -5,12 +5,10 @@ from homeassistant.components.fan import ( FanEntity, + FanEntityFeature, PLATFORM_SCHEMA, DIRECTION_REVERSE, DIRECTION_FORWARD, - SUPPORT_SET_SPEED, - SUPPORT_DIRECTION, - SUPPORT_OSCILLATE, ) from homeassistant.const import CONF_NAME, STATE_OFF, STATE_ON, STATE_UNKNOWN from homeassistant.core import HomeAssistant, Event, EventStateChangedData @@ -40,7 +38,9 @@ SPEED_OFF = "off" OSCILLATING = "oscillate" -SUPPORT_FLAGS = SUPPORT_SET_SPEED +SUPPORT_FLAGS = FanEntityFeature.SET_SPEED +SUPPORT_DIRECTION = FanEntityFeature.DIRECTION +SUPPORT_OSCILLATE = FanEntityFeature.OSCILLATE PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { From a409ed89cd2419330dfa035a02522a694894377d Mon Sep 17 00:00:00 2001 From: h3nrytan Date: Sun, 9 Jun 2024 10:27:24 +0800 Subject: [PATCH 2/2] replace old constant names by the new enum FanEntityFeature in the whole code --- custom_components/smartir/fan.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/custom_components/smartir/fan.py b/custom_components/smartir/fan.py index 2ee3a4ca..30f4e412 100644 --- a/custom_components/smartir/fan.py +++ b/custom_components/smartir/fan.py @@ -38,10 +38,6 @@ SPEED_OFF = "off" OSCILLATING = "oscillate" -SUPPORT_FLAGS = FanEntityFeature.SET_SPEED -SUPPORT_DIRECTION = FanEntityFeature.DIRECTION -SUPPORT_OSCILLATE = FanEntityFeature.OSCILLATE - PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Optional(CONF_UNIQUE_ID): cv.string, @@ -103,14 +99,14 @@ def __init__(self, hass, config, device_data): self._current_direction = None self._last_on_speed = None self._oscillating = None - self._support_flags = SUPPORT_FLAGS + self._support_flags = FanEntityFeature.SET_SPEED if DIRECTION_REVERSE in self._commands and DIRECTION_FORWARD in self._commands: self._current_direction = DIRECTION_REVERSE - self._support_flags = self._support_flags | SUPPORT_DIRECTION + self._support_flags = self._support_flags | FanEntityFeature.DIRECTION if OSCILLATING in self._commands: self._oscillating = False - self._support_flags = self._support_flags | SUPPORT_OSCILLATE + self._support_flags = self._support_flags | FanEntityFeature.OSCILLATE self._temp_lock = asyncio.Lock() self._on_by_remote = False @@ -135,16 +131,16 @@ async def async_added_to_hass(self): self._speed = last_state.attributes["speed"] # If _direction has a value the direction controls appears - # in UI even if SUPPORT_DIRECTION is not provided in the flags + # in UI even if FanEntityFeature.DIRECTION is not provided in the flags if ( "current_direction" in last_state.attributes - and self._support_flags & SUPPORT_DIRECTION + and self._support_flags & FanEntityFeature.DIRECTION ): self._current_direction = last_state.attributes["current_direction"] if ( "oscillating" in last_state.attributes - and self._support_flags & SUPPORT_OSCILLATE + and self._support_flags & FanEntityFeature.OSCILLATE ): self._oscillating = last_state.attributes["oscillating"]