Skip to content

Commit

Permalink
Merge pull request #779 from smartHomeHub/rc
Browse files Browse the repository at this point in the history
1.17.5
  • Loading branch information
vassilis-panos authored Feb 7, 2022
2 parents 2cf300f + 471c155 commit 11393a6
Show file tree
Hide file tree
Showing 3 changed files with 36 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.4'
VERSION = '1.17.5'
MANIFEST_URL = (
"https://raw.githubusercontent.com/"
"smartHomeHub/SmartIR/{}/"
Expand Down
50 changes: 31 additions & 19 deletions custom_components/smartir/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
from homeassistant.helpers.event import async_track_state_change
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.util.percentage import (
ordered_list_item_to_percentage,
percentage_to_ordered_list_item
)
from . import COMPONENT_ABS_DIR, Helper
from .controller import get_controller

Expand Down Expand Up @@ -93,7 +97,7 @@ def __init__(self, hass, config, device_data):
self._supported_models = device_data['supportedModels']
self._supported_controller = device_data['supportedController']
self._commands_encoding = device_data['commandsEncoding']
self._speed_list = [SPEED_OFF] + device_data['speed']
self._speed_list = device_data['speed']
self._commands = device_data['commands']

self._speed = SPEED_OFF
Expand Down Expand Up @@ -161,19 +165,22 @@ def name(self):
def state(self):
"""Return the current state."""
if (self._on_by_remote or \
self.speed != SPEED_OFF):
self._speed != SPEED_OFF):
return STATE_ON
return SPEED_OFF

@property
def speed_list(self):
"""Get the list of available speeds."""
return self._speed_list
def percentage(self):
"""Return speed percentage of the fan."""
if (self._speed == SPEED_OFF):
return 0

return ordered_list_item_to_percentage(self._speed_list, self._speed)

@property
def speed(self):
"""Return the current speed."""
return self._speed
def speed_count(self):
"""Return the number of speeds the fan supports."""
return len(self._speed_list)

@property
def oscillating(self):
Expand Down Expand Up @@ -207,12 +214,16 @@ def extra_state_attributes(self):
'commands_encoding': self._commands_encoding,
}

async def async_set_speed(self, speed: str):
"""Set the speed of the fan."""
self._speed = speed
async def async_set_percentage(self, percentage: int):
"""Set the desired speed for the fan."""
if (percentage == 0):
self._speed = SPEED_OFF
else:
self._speed = percentage_to_ordered_list_item(
self._speed_list, percentage)

if not speed == SPEED_OFF:
self._last_on_speed = speed
if not self._speed == SPEED_OFF:
self._last_on_speed = self._speed

await self.send_command()
await self.async_update_ha_state()
Expand All @@ -233,16 +244,17 @@ async def async_set_direction(self, direction: str):

await self.async_update_ha_state()

async def async_turn_on(self, speed: str = None, **kwargs):
async def async_turn_on(self, percentage: int = None, **kwargs):
"""Turn on the fan."""
if speed is None:
speed = self._last_on_speed or self._speed_list[1]
if percentage is None:
percentage = ordered_list_item_to_percentage(
self._speed_list, self._last_on_speed or self._speed_list[0])

await self.async_set_speed(speed)
await self.async_set_percentage(percentage)

async def async_turn_off(self):
"""Turn off the fan."""
await self.async_set_speed(SPEED_OFF)
await self.async_set_percentage(0)

async def send_command(self):
async with self._temp_lock:
Expand Down Expand Up @@ -280,4 +292,4 @@ async def _async_power_sensor_changed(self, entity_id, old_state, new_state):
self._on_by_remote = False
if self._speed != SPEED_OFF:
self._speed = SPEED_OFF
await self.async_update_ha_state()
await self.async_update_ha_state()
8 changes: 4 additions & 4 deletions custom_components/smartir/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"dependencies": [],
"codeowners": ["@smartHomeHub"],
"requirements": ["aiofiles==0.6.0"],
"homeassistant": "0.115.0",
"version": "1.17.4",
"homeassistant": "2022.2.0",
"version": "1.17.5",
"updater": {
"version": "1.17.4",
"releaseNotes": "-- Fixed typo #764",
"version": "1.17.5",
"releaseNotes": "-- Compliance with the breaking change of the new fan model",
"files": [
"__init__.py",
"climate.py",
Expand Down

0 comments on commit 11393a6

Please sign in to comment.