[go: nahoru, domu]

Skip to content

Commit

Permalink
Replace deprecated constants which will be removed in 2025.1 (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
r08ertliu committed Mar 7, 2024
1 parent 9ca33e5 commit 6fc10b3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 35 deletions.
54 changes: 23 additions & 31 deletions custom_components/jcihitachi_tw/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,10 @@
from homeassistant.components.climate.const import (FAN_AUTO, FAN_DIFFUSE,
FAN_FOCUS, FAN_HIGH,
FAN_LOW, FAN_MEDIUM,
HVAC_MODE_AUTO,
HVAC_MODE_COOL,
HVAC_MODE_DRY,
HVAC_MODE_FAN_ONLY,
HVAC_MODE_HEAT,
HVAC_MODE_OFF,
HVACMode,
PRESET_BOOST, PRESET_ECO,
PRESET_NONE,
SUPPORT_FAN_MODE,
SUPPORT_PRESET_MODE,
SUPPORT_SWING_MODE,
SUPPORT_TARGET_TEMPERATURE,
ClimateEntityFeature,
SWING_BOTH,
SWING_HORIZONTAL,
SWING_OFF, SWING_VERTICAL)
Expand Down Expand Up @@ -66,12 +58,12 @@
]

SUPPORT_HVAC = [
HVAC_MODE_OFF,
HVAC_MODE_COOL,
HVAC_MODE_DRY,
HVAC_MODE_FAN_ONLY,
HVAC_MODE_AUTO,
HVAC_MODE_HEAT,
HVACMode.OFF,
HVACMode.COOL,
HVACMode.DRY,
HVACMode.FAN_ONLY,
HVACMode.AUTO,
HVACMode.HEAT,
]


Expand Down Expand Up @@ -159,17 +151,17 @@ def hvac_mode(self):
status = self.hass.data[DOMAIN][UPDATED_DATA][self._thing.name]
if status:
if status.power == "off":
return HVAC_MODE_OFF
return HVACMode.OFF
elif status.mode == "cool":
return HVAC_MODE_COOL
return HVACMode.COOL
elif status.mode == "dry":
return HVAC_MODE_DRY
return HVACMode.DRY
elif status.mode == "fan":
return HVAC_MODE_FAN_ONLY
return HVACMode.FAN_ONLY
elif status.mode == "auto":
return HVAC_MODE_AUTO
return HVACMode.AUTO
elif status.mode == "heat":
return HVAC_MODE_HEAT
return HVACMode.HEAT

_LOGGER.error("Missing hvac_mode")
return None
Expand Down Expand Up @@ -264,10 +256,10 @@ def unique_id(self):
return f"{self._thing.gateway_mac_address}_climate"

def calculate_supported_features(self):
support_flags = SUPPORT_TARGET_TEMPERATURE | SUPPORT_FAN_MODE | SUPPORT_PRESET_MODE
support_flags = ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE | ClimateEntityFeature.PRESET_MODE
if self._thing.support_code.HorizontalWindDirectionSetting != "unsupported" and \
self._thing.support_code.VerticalWindDirectionSwitch != "unsupported":
support_flags |= SUPPORT_SWING_MODE
support_flags |= ClimateEntityFeature.SWING_MODE
return support_flags

def calculate_supported_presets(self):
Expand Down Expand Up @@ -297,20 +289,20 @@ def set_hvac_mode(self, hvac_mode):
_LOGGER.debug(f"Set {self.name} hvac_mode to {hvac_mode}")

status = self.hass.data[DOMAIN][UPDATED_DATA][self._thing.name]
if status.power == "off" and hvac_mode != HVAC_MODE_OFF:
if status.power == "off" and hvac_mode != HVACMode.OFF:
self.put_queue(status_name="power", status_str_value="on")

if hvac_mode == HVAC_MODE_OFF:
if hvac_mode == HVACMode.OFF:
self.put_queue(status_name="power", status_str_value="off")
elif hvac_mode == HVAC_MODE_COOL:
elif hvac_mode == HVACMode.COOL:
self.put_queue(status_name="mode", status_str_value="cool")
elif hvac_mode == HVAC_MODE_DRY:
elif hvac_mode == HVACMode.DRY:
self.put_queue(status_name="mode", status_str_value="dry")
elif hvac_mode == HVAC_MODE_FAN_ONLY:
elif hvac_mode == HVACMode.FAN_ONLY:
self.put_queue(status_name="mode", status_str_value="fan")
elif hvac_mode == HVAC_MODE_AUTO:
elif hvac_mode == HVACMode.AUTO:
self.put_queue(status_name="mode", status_str_value="auto")
elif hvac_mode == HVAC_MODE_HEAT:
elif hvac_mode == HVACMode.HEAT:
self.put_queue(status_name="mode", status_str_value="heat")
else:
_LOGGER.error("Invalid hvac_mode.")
Expand Down
4 changes: 2 additions & 2 deletions custom_components/jcihitachi_tw/humidifier.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""JciHitachi integration."""
import logging

from homeassistant.components.humidifier import (SUPPORT_MODES,
from homeassistant.components.humidifier import (HumidifierEntityFeature,
HumidifierDeviceClass,
HumidifierEntity)

Expand Down Expand Up @@ -146,7 +146,7 @@ def unique_id(self):

@staticmethod
def calculate_supported_features(status):
support_flags = SUPPORT_MODES
support_flags = HumidifierEntityFeature.MODES
return support_flags

def set_mode(self, mode):
Expand Down
4 changes: 2 additions & 2 deletions custom_components/jcihitachi_tw/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import datetime
import logging

from homeassistant.components.sensor import (STATE_CLASS_TOTAL_INCREASING,
from homeassistant.components.sensor import (SensorStateClass,
SensorDeviceClass, SensorEntity)
from homeassistant.const import (CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
PERCENTAGE, UnitOfEnergy, UnitOfTemperature)
Expand Down Expand Up @@ -193,7 +193,7 @@ def unique_id(self):

@property
def state_class(self):
return STATE_CLASS_TOTAL_INCREASING
return SensorStateClass.TOTAL_INCREASING

class JciHitachiMonthlyPowerConsumptionSensorEntity(JciHitachiEntity, SensorEntity):
def __init__(self, thing, coordinator):
Expand Down

0 comments on commit 6fc10b3

Please sign in to comment.