Skip to content

Commit c1670f0

Browse files
committed
Refactor Myio integration to align with updated HA constants.
Replaced deprecated constants with their current equivalents from Home Assistant's API, such as `UnitOfTemperature`, `HVACMode`, and `HVACAction`. Updated `sensor.py` and `climate.py` with standardized property usage, improving compatibility with future HA versions. Also, adjusted README to reflect the latest tested version.
1 parent b4da95a commit c1670f0

File tree

3 files changed

+66
-60
lines changed

3 files changed

+66
-60
lines changed

README.MD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
MYIO is a home automation platform (<a href="http://smarthomeninja.hu" target="_blank">MYIO home page</a>). This repository provides integration of this platform to Home Assistant.
44

5-
Latest tested Home Assistant version: <b>2024.8</b>
5+
Latest tested Home Assistant version: <b>2025.1</b>
66

77
## License
88

myio/climate.py

Lines changed: 62 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
from homeassistant.components.climate.const import (
99
ATTR_TARGET_TEMP_HIGH,
1010
ATTR_TARGET_TEMP_LOW,
11-
CURRENT_HVAC_COOL,
12-
CURRENT_HVAC_HEAT,
13-
CURRENT_HVAC_IDLE,
14-
HVAC_MODE_COOL,
15-
HVAC_MODE_HEAT,
16-
SUPPORT_TARGET_TEMPERATURE_RANGE,
11+
DEFAULT_MIN_TEMP,
12+
DEFAULT_MAX_TEMP,
13+
ClimateEntityFeature,
1714
)
18-
from homeassistant.const import CONF_NAME, TEMP_CELSIUS
15+
from homeassistant.components.climate.const import HVACAction
16+
from homeassistant.components.climate.const import HVACMode
17+
from homeassistant.const import CONF_NAME
18+
from homeassistant.const import UnitOfTemperature
1919
from homeassistant.util import slugify
2020

2121
from .const import DOMAIN
@@ -114,49 +114,53 @@ def id_converter(_eeprom_id):
114114
/ 10
115115
)
116116

117+
self._min_temp = DEFAULT_MIN_TEMP
118+
self._max_temp = DEFAULT_MAX_TEMP
119+
117120
"""Set hvac_mode if it is in cool or heat mode."""
118-
self._hvac_modes = [HVAC_MODE_COOL, HVAC_MODE_HEAT]
121+
self._hvac_modes = [HVACMode.COOL, HVACMode.HEAT]
119122
if self._sensor_off > self._sensor_on:
120-
self._hvac_mode = HVAC_MODE_HEAT
123+
self._hvac_mode = HVACMode.HEAT
121124
else:
122-
self._hvac_mode = HVAC_MODE_COOL
123-
if self._hvac_mode == HVAC_MODE_HEAT:
125+
self._hvac_mode = HVACMode.COOL
126+
if self._hvac_mode == HVACMode.HEAT:
124127
self._target_temperature_high = self._sensor_off
125128
self._target_temperature_low = self._sensor_on
126-
self._min_temp = (self._sensor_off + self._sensor_on) / 2 - (
127-
self._sensor_off - self._sensor_on
128-
)
129-
self._max_temp = (self._sensor_off + self._sensor_on) / 2 + (
130-
self._sensor_off - self._sensor_on
131-
)
132-
if self._min_temp + 1 > self._sensor_on:
133-
self._min_temp = self._sensor_on - 1
134-
if self._max_temp - 1 < self._sensor_off:
135-
self._max_temp = self._sensor_off + 1
129+
# self._min_temp = (self._sensor_off + self._sensor_on) / 2 - (
130+
# self._sensor_off - self._sensor_on
131+
# )
132+
# self._max_temp = (self._sensor_off + self._sensor_on) / 2 + (
133+
# self._sensor_off - self._sensor_on
134+
# )
135+
# if self._min_temp + 1 > self._sensor_on:
136+
# self._min_temp = self._sensor_on - 1
137+
# if self._max_temp - 1 < self._sensor_off:
138+
# self._max_temp = self._sensor_off + 1
136139
else:
137140
self._target_temperature_high = self._sensor_on
138141
self._target_temperature_low = self._sensor_off
139-
self._min_temp = (self._sensor_off + self._sensor_on) / 2 - (
140-
self._sensor_on - self._sensor_off
141-
)
142-
self._max_temp = (self._sensor_off + self._sensor_on) / 2 + (
143-
self._sensor_on - self._sensor_off
144-
)
145-
if self._state != 0 and self._hvac_mode == HVAC_MODE_HEAT:
146-
self._hvac_action = CURRENT_HVAC_HEAT
147-
if self._state != 0 and self._hvac_mode == HVAC_MODE_COOL:
148-
self._hvac_action = CURRENT_HVAC_COOL
142+
# self._min_temp = (self._sensor_off + self._sensor_on) / 2 - (
143+
# self._sensor_on - self._sensor_off
144+
# )
145+
# self._max_temp = (self._sensor_off + self._sensor_on) / 2 + (
146+
# self._sensor_on - self._sensor_off
147+
# )
148+
if self._state != 0 and self._hvac_mode == HVACMode.HEAT:
149+
self._hvac_action = HVACAction.HEATING
150+
if self._state != 0 and self._hvac_mode == HVACMode.COOL:
151+
self._hvac_action = HVACAction.COOLING
149152
if self._state == 0:
150-
self._hvac_action = CURRENT_HVAC_IDLE
153+
self._hvac_action = HVACAction.IDLE
154+
151155
if int(self._sensor) <= 100:
152-
self._unit_of_measurement = TEMP_CELSIUS
156+
self._unit_of_measurement = UnitOfTemperature.CELSIUS
153157
self._target_temperature_step = 0.1
154158
self._precision = 0.1
155159
self._current_temperature = (
156160
self._server_data["sensors"][self._sensor]["temp"] / 100
157161
)
158162
elif int(self._sensor) <= 200:
159-
self._unit_of_measurement = TEMP_CELSIUS
163+
self._unit_of_measurement = UnitOfTemperature.CELSIUS
160164
self._target_temperature_step = 1
161165
self._precision = 1
162166
self._current_temperature = (
@@ -172,7 +176,7 @@ def id_converter(_eeprom_id):
172176
]
173177
# define SUPPORT_FLAGS
174178
self._support_flags = SUPPORT_FLAGS
175-
self._support_flags = self._support_flags | SUPPORT_TARGET_TEMPERATURE_RANGE
179+
self._support_flags = self._support_flags | ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
176180

177181
@property
178182
def should_poll(self) -> bool:
@@ -298,7 +302,7 @@ async def async_set_temperature(self, **kwargs):
298302
self._target_temperature_low = kwargs.get(ATTR_TARGET_TEMP_LOW)
299303
_string_on = ""
300304
_string_off = ""
301-
if self._hvac_mode == HVAC_MODE_HEAT:
305+
if self._hvac_mode == HVACMode.HEAT:
302306
if self._output == "relays":
303307
_string_on = "min_temp_ON"
304308
_string_off = "max_temp_OFF"
@@ -348,10 +352,10 @@ async def async_update(self):
348352
self._id - self._id_mod)]["sensorOFF"]
349353
> self._server_data[self._output][str(self._id - self._id_mod)]["sensorON"]
350354
):
351-
self._hvac_mode = HVAC_MODE_HEAT
355+
self._hvac_mode = HVACMode.HEAT
352356
else:
353-
self._hvac_mode = HVAC_MODE_COOL
354-
if self._hvac_mode == HVAC_MODE_HEAT:
357+
self._hvac_mode = HVACMode.COOL
358+
if self._hvac_mode == HVACMode.HEAT:
355359
self._target_temperature_low = (
356360
self._server_data[self._output][str(self._id - self._id_mod)][
357361
"sensorON"
@@ -364,7 +368,7 @@ async def async_update(self):
364368
]
365369
/ 10
366370
)
367-
if self._hvac_mode == HVAC_MODE_COOL:
371+
if self._hvac_mode == HVACMode.COOL:
368372
self._target_temperature_low = (
369373
self._server_data[self._output][str(self._id - self._id_mod)][
370374
"sensorOFF"
@@ -377,23 +381,24 @@ async def async_update(self):
377381
]
378382
/ 10
379383
)
380-
self._min_temp = (
381-
self._target_temperature_high + self._target_temperature_low
382-
) / 2 - (self._target_temperature_high - self._target_temperature_low)
383-
self._max_temp = (
384-
self._target_temperature_high + self._target_temperature_low
385-
) / 2 + (self._target_temperature_high - self._target_temperature_low)
386-
387-
if self._min_temp + 1 > self._target_temperature_low:
388-
self._min_temp = self._target_temperature_low - 1
389-
if self._max_temp - 1 < self._target_temperature_high:
390-
self._max_temp = self._target_temperature_high + 1
391-
392-
if self._state != 0 and self._hvac_mode == HVAC_MODE_HEAT:
393-
self._hvac_action = CURRENT_HVAC_HEAT
394-
if self._state != 0 and self._hvac_mode == HVAC_MODE_COOL:
395-
self._hvac_action = CURRENT_HVAC_COOL
384+
# self._min_temp = (
385+
# self._target_temperature_high + self._target_temperature_low
386+
# ) / 2 - (self._target_temperature_high - self._target_temperature_low)
387+
# self._max_temp = (
388+
# self._target_temperature_high + self._target_temperature_low
389+
# ) / 2 + (self._target_temperature_high - self._target_temperature_low)
390+
#
391+
# if self._min_temp + 1 > self._target_temperature_low:
392+
# self._min_temp = self._target_temperature_low - 1
393+
# if self._max_temp - 1 < self._target_temperature_high:
394+
# self._max_temp = self._target_temperature_high + 1
395+
396+
if self._state != 0 and self._hvac_mode == HVACMode.HEAT:
397+
self._hvac_action = HVACAction.HEATING
398+
if self._state != 0 and self._hvac_mode == HVACMode.COOL:
399+
self._hvac_action = HVACAction.COOLING
396400
if self._state == 0:
397-
self._hvac_action = CURRENT_HVAC_IDLE
401+
self._hvac_action = HVACAction.IDLE
402+
398403

399404
self.schedule_update_ha_state()

myio/sensor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from datetime import timedelta
33
import logging
44

5-
from homeassistant.const import CONF_NAME, PERCENTAGE, TEMP_CELSIUS
5+
from homeassistant.const import CONF_NAME, PERCENTAGE
6+
from homeassistant.const import UnitOfTemperature
67
from homeassistant.helpers.entity import Entity
78
from homeassistant.util import slugify
89

@@ -87,7 +88,7 @@ def state(self):
8788
def unit_of_measurement(self):
8889
"""Return the unit of measurement."""
8990
if int(self._number) < 100:
90-
string_to_send = TEMP_CELSIUS
91+
string_to_send = UnitOfTemperature.CELSIUS
9192
elif int(self._number) < 200:
9293
string_to_send = PERCENTAGE
9394
else:

0 commit comments

Comments
 (0)