Skip to content

Commit

Permalink
ClimateEntityFeature enum compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
vassilis-panos committed Dec 29, 2024
1 parent 217dfd0 commit a6a3ee6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 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.9'
VERSION = '1.17.10'
MANIFEST_URL = (
"https://raw.githubusercontent.com/"
"smartHomeHub/SmartIR/{}/"
Expand Down
39 changes: 19 additions & 20 deletions custom_components/smartir/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

from homeassistant.components.climate import ClimateEntity, PLATFORM_SCHEMA
from homeassistant.components.climate.const import (
HVAC_MODE_OFF, HVAC_MODE_HEAT, HVAC_MODE_COOL,
HVAC_MODE_DRY, HVAC_MODE_FAN_ONLY, HVAC_MODE_AUTO,
SUPPORT_TARGET_TEMPERATURE, SUPPORT_FAN_MODE,
SUPPORT_SWING_MODE, HVAC_MODES, ATTR_HVAC_MODE)
ClimateEntityFeature, HVACMode, HVAC_MODES, ATTR_HVAC_MODE)
from homeassistant.const import (
CONF_NAME, STATE_ON, STATE_OFF, STATE_UNKNOWN, STATE_UNAVAILABLE, ATTR_TEMPERATURE,
PRECISION_TENTHS, PRECISION_HALVES, PRECISION_WHOLE)
Expand All @@ -36,8 +33,10 @@
CONF_POWER_SENSOR_RESTORE_STATE = 'power_sensor_restore_state'

SUPPORT_FLAGS = (
SUPPORT_TARGET_TEMPERATURE |
SUPPORT_FAN_MODE
ClimateEntityFeature.TURN_OFF |
ClimateEntityFeature.TURN_ON |
ClimateEntityFeature.TARGET_TEMPERATURE |
ClimateEntityFeature.FAN_MODE
)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
Expand Down Expand Up @@ -119,13 +118,13 @@ def __init__(self, hass, config, device_data):

valid_hvac_modes = [x for x in device_data['operationModes'] if x in HVAC_MODES]

self._operation_modes = [HVAC_MODE_OFF] + valid_hvac_modes
self._operation_modes = [HVACMode.OFF] + valid_hvac_modes
self._fan_modes = device_data['fanModes']
self._swing_modes = device_data.get('swingModes')
self._commands = device_data['commands']

self._target_temperature = self._min_temperature
self._hvac_mode = HVAC_MODE_OFF
self._hvac_mode = HVACMode.OFF
self._current_fan_mode = self._fan_modes[0]
self._current_swing_mode = None
self._last_on_operation = None
Expand All @@ -140,7 +139,7 @@ def __init__(self, hass, config, device_data):
self._support_swing = False

if self._swing_modes:
self._support_flags = self._support_flags | SUPPORT_SWING_MODE
self._support_flags = self._support_flags | ClimateEntityFeature.SWING_MODE
self._current_swing_mode = self._swing_modes[0]
self._support_swing = True

Expand Down Expand Up @@ -204,9 +203,9 @@ def name(self):
@property
def state(self):
"""Return the current state."""
if self.hvac_mode != HVAC_MODE_OFF:
if self.hvac_mode != HVACMode.OFF:
return self.hvac_mode
return HVAC_MODE_OFF
return HVACMode.OFF

@property
def temperature_unit(self):
Expand Down Expand Up @@ -316,7 +315,7 @@ async def async_set_temperature(self, **kwargs):
await self.async_set_hvac_mode(hvac_mode)
return

if not self._hvac_mode.lower() == HVAC_MODE_OFF:
if not self._hvac_mode.lower() == HVACMode.OFF:
await self.send_command()

self.async_write_ha_state()
Expand All @@ -325,7 +324,7 @@ async def async_set_hvac_mode(self, hvac_mode):
"""Set operation mode."""
self._hvac_mode = hvac_mode

if not hvac_mode == HVAC_MODE_OFF:
if not hvac_mode == HVACMode.OFF:
self._last_on_operation = hvac_mode

await self.send_command()
Expand All @@ -335,21 +334,21 @@ async def async_set_fan_mode(self, fan_mode):
"""Set fan mode."""
self._current_fan_mode = fan_mode

if not self._hvac_mode.lower() == HVAC_MODE_OFF:
if not self._hvac_mode.lower() == HVACMode.OFF:
await self.send_command()
self.async_write_ha_state()

async def async_set_swing_mode(self, swing_mode):
"""Set swing mode."""
self._current_swing_mode = swing_mode

if not self._hvac_mode.lower() == HVAC_MODE_OFF:
if not self._hvac_mode.lower() == HVACMode.OFF:
await self.send_command()
self.async_write_ha_state()

async def async_turn_off(self):
"""Turn off."""
await self.async_set_hvac_mode(HVAC_MODE_OFF)
await self.async_set_hvac_mode(HVACMode.OFF)

async def async_turn_on(self):
"""Turn on."""
Expand All @@ -367,7 +366,7 @@ async def send_command(self):
swing_mode = self._current_swing_mode
target_temperature = '{0:g}'.format(self._target_temperature)

if operation_mode.lower() == HVAC_MODE_OFF:
if operation_mode.lower() == HVACMode.OFF:
await self._controller.send(self._commands['off'])
return

Expand Down Expand Up @@ -409,7 +408,7 @@ async def _async_power_sensor_changed(self, entity_id, old_state, new_state):
if old_state is not None and new_state.state == old_state.state:
return

if new_state.state == STATE_ON and self._hvac_mode == HVAC_MODE_OFF:
if new_state.state == STATE_ON and self._hvac_mode == HVACMode.OFF:
self._on_by_remote = True
if self._power_sensor_restore_state == True and self._last_on_operation is not None:
self._hvac_mode = self._last_on_operation
Expand All @@ -420,8 +419,8 @@ async def _async_power_sensor_changed(self, entity_id, old_state, new_state):

if new_state.state == STATE_OFF:
self._on_by_remote = False
if self._hvac_mode != HVAC_MODE_OFF:
self._hvac_mode = HVAC_MODE_OFF
if self._hvac_mode != HVACMode.OFF:
self._hvac_mode = HVACMode.OFF
self.async_write_ha_state()

@callback
Expand Down
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": "2023.12.0",
"version": "1.17.9",
"homeassistant": "2024.10.0",
"version": "1.17.10",
"updater": {
"version": "1.17.9",
"releaseNotes": "-- Fix Fan.async_turn_on() #1170",
"version": "1.17.10",
"releaseNotes": "-- ClimateEntityFeature enum compatibility",
"files": [
"__init__.py",
"climate.py",
Expand Down

0 comments on commit a6a3ee6

Please sign in to comment.