Skip to content

Commit

Permalink
Merge pull request #26 from gurglingtonic/patch-1
Browse files Browse the repository at this point in the history
fix fan constants deprecation in HA 2024.6.0
  • Loading branch information
litinoveweedle authored Jun 9, 2024
2 parents 78bf972 + a409ed8 commit 9c57403
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions custom_components/smartir/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -40,8 +38,6 @@
SPEED_OFF = "off"
OSCILLATING = "oscillate"

SUPPORT_FLAGS = SUPPORT_SET_SPEED

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Optional(CONF_UNIQUE_ID): cv.string,
Expand Down Expand Up @@ -104,14 +100,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
Expand All @@ -136,16 +132,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"]

Expand Down

0 comments on commit 9c57403

Please sign in to comment.