Skip to content

Commit

Permalink
Fixes media_player and fan attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
vassilis-panos committed Jan 4, 2025
1 parent 99b0c61 commit 3cd1e77
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion custom_components/smartir/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
_LOGGER = logging.getLogger(__name__)

DOMAIN = 'smartir'
VERSION = '1.17.11'
VERSION = '1.17.12'
MANIFEST_URL = (
"https://raw.githubusercontent.com/"
"smartHomeHub/SmartIR/{}/"
Expand Down
14 changes: 6 additions & 8 deletions custom_components/smartir/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
import voluptuous as vol

from homeassistant.components.fan import (
FanEntity, PLATFORM_SCHEMA,
DIRECTION_REVERSE, DIRECTION_FORWARD,
SUPPORT_SET_SPEED, SUPPORT_DIRECTION, SUPPORT_OSCILLATE,
ATTR_OSCILLATING)
FanEntity, FanEntityFeature,
PLATFORM_SCHEMA, DIRECTION_REVERSE, DIRECTION_FORWARD)
from homeassistant.const import (
CONF_NAME, STATE_OFF, STATE_ON, STATE_UNKNOWN)
from homeassistant.core import callback
Expand Down Expand Up @@ -110,17 +108,17 @@ def __init__(self, hass, config, device_data):
self._direction = None
self._last_on_speed = None
self._oscillating = None
self._support_flags = SUPPORT_SET_SPEED
self._support_flags = FanEntityFeature.SET_SPEED

if (DIRECTION_REVERSE in self._commands and \
DIRECTION_FORWARD in self._commands):
self._direction = DIRECTION_REVERSE
self._support_flags = (
self._support_flags | SUPPORT_DIRECTION)
self._support_flags | FanEntityFeature.DIRECTION)
if ('oscillate' in self._commands):
self._oscillating = False
self._support_flags = (
self._support_flags | SUPPORT_OSCILLATE)
self._support_flags | FanEntityFeature.OSCILLATE)


self._temp_lock = asyncio.Lock()
Expand All @@ -147,7 +145,7 @@ async def async_added_to_hass(self):
#If _direction has a value the direction controls appears
#in UI even if SUPPORT_DIRECTION is not provided in the flags
if ('direction' in last_state.attributes and \
self._support_flags & SUPPORT_DIRECTION):
self._support_flags & FanEntityFeature.DIRECTION):
self._direction = last_state.attributes['direction']

if 'last_on_speed' in last_state.attributes:
Expand Down
6 changes: 3 additions & 3 deletions custom_components/smartir/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"codeowners": ["@smartHomeHub"],
"requirements": ["aiofiles>=0.6.0"],
"homeassistant": "2024.10.0",
"version": "1.17.11",
"version": "1.17.12",
"updater": {
"version": "1.17.11",
"releaseNotes": "-- Implements asynchronous device file loading",
"version": "1.17.12",
"releaseNotes": "-- Fixes media_player and fan attributes",
"files": [
"__init__.py",
"climate.py",
Expand Down
22 changes: 10 additions & 12 deletions custom_components/smartir/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
from homeassistant.components.media_player import (
MediaPlayerEntity, PLATFORM_SCHEMA)
from homeassistant.components.media_player.const import (
SUPPORT_TURN_OFF, SUPPORT_TURN_ON, SUPPORT_PREVIOUS_TRACK,
SUPPORT_NEXT_TRACK, SUPPORT_VOLUME_STEP, SUPPORT_VOLUME_MUTE,
SUPPORT_PLAY_MEDIA, SUPPORT_SELECT_SOURCE, MEDIA_TYPE_CHANNEL)
MediaPlayerEntityFeature, MediaType)
from homeassistant.const import (
CONF_NAME, STATE_OFF, STATE_ON, STATE_UNKNOWN)
import homeassistant.helpers.config_validation as cv
Expand Down Expand Up @@ -112,26 +110,26 @@ def __init__(self, hass, config, device_data):

#Supported features
if 'off' in self._commands and self._commands['off'] is not None:
self._support_flags = self._support_flags | SUPPORT_TURN_OFF
self._support_flags = self._support_flags | MediaPlayerEntityFeature.TURN_OFF

if 'on' in self._commands and self._commands['on'] is not None:
self._support_flags = self._support_flags | SUPPORT_TURN_ON
self._support_flags = self._support_flags | MediaPlayerEntityFeature.TURN_ON

if 'previousChannel' in self._commands and self._commands['previousChannel'] is not None:
self._support_flags = self._support_flags | SUPPORT_PREVIOUS_TRACK
self._support_flags = self._support_flags | MediaPlayerEntityFeature.PREVIOUS_TRACK

if 'nextChannel' in self._commands and self._commands['nextChannel'] is not None:
self._support_flags = self._support_flags | SUPPORT_NEXT_TRACK
self._support_flags = self._support_flags | MediaPlayerEntityFeature.NEXT_TRACK

if ('volumeDown' in self._commands and self._commands['volumeDown'] is not None) \
or ('volumeUp' in self._commands and self._commands['volumeUp'] is not None):
self._support_flags = self._support_flags | SUPPORT_VOLUME_STEP
self._support_flags = self._support_flags | MediaPlayerEntityFeature.VOLUME_STEP

if 'mute' in self._commands and self._commands['mute'] is not None:
self._support_flags = self._support_flags | SUPPORT_VOLUME_MUTE
self._support_flags = self._support_flags | MediaPlayerEntityFeature.VOLUME_MUTE

if 'sources' in self._commands and self._commands['sources'] is not None:
self._support_flags = self._support_flags | SUPPORT_SELECT_SOURCE | SUPPORT_PLAY_MEDIA
self._support_flags = self._support_flags | MediaPlayerEntityFeature.SELECT_SOURCE | MediaPlayerEntityFeature.PLAY_MEDIA

for source, new_name in config.get(CONF_SOURCE_NAMES, {}).items():
if source in self._commands['sources']:
Expand Down Expand Up @@ -196,7 +194,7 @@ def media_title(self):
@property
def media_content_type(self):
"""Content type of current playing media."""
return MEDIA_TYPE_CHANNEL
return MediaType.CHANNEL

@property
def source_list(self):
Expand Down Expand Up @@ -275,7 +273,7 @@ async def async_play_media(self, media_type, media_id, **kwargs):
if self._state == STATE_OFF:
await self.async_turn_on()

if media_type != MEDIA_TYPE_CHANNEL:
if media_type != MediaType.CHANNEL:
_LOGGER.error("invalid media type")
return
if not media_id.isdigit():
Expand Down

0 comments on commit 3cd1e77

Please sign in to comment.