Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update fan.py #26

Merged
merged 2 commits into from
Jun 9, 2024
Merged
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
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 @@ -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
Expand All @@ -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"]

Expand Down
Loading