Skip to content

Commit

Permalink
Merge pull request #95 from MTrab:Fix-deprecated-constants
Browse files Browse the repository at this point in the history
Update deprecated constants
  • Loading branch information
MTrab committed Feb 5, 2024
2 parents adf0fc6 + 27dda72 commit 642d3b8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 31 deletions.
36 changes: 17 additions & 19 deletions custom_components/danfoss_ally/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
from homeassistant.components.climate.const import ( # SUPPORT_PRESET_MODE,; SUPPORT_TARGET_TEMPERATURE,
ATTR_HVAC_MODE,
ATTR_PRESET_MODE,
CURRENT_HVAC_HEAT,
CURRENT_HVAC_IDLE,
HVAC_MODE_AUTO,
HVAC_MODE_HEAT,
HVACAction,
PRESET_AWAY,
PRESET_HOME,
HVACMode,
ClimateEntityFeature,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers import entity_platform
Expand Down Expand Up @@ -170,13 +168,13 @@ def hvac_mode(self):
or self._device["mode"] == "leaving_home"
or self._device["mode"] == "holiday_sat"
):
return HVAC_MODE_AUTO
return HVACMode.AUTO
elif (
self._device["mode"] == "manual"
or self._device["mode"] == "pause"
or self._device["mode"] == "holiday"
):
return HVAC_MODE_HEAT
return HVACMode.HEAT

@property
def preset_mode(self):
Expand Down Expand Up @@ -237,18 +235,18 @@ def set_preset_mode(self, preset_mode):
@property
def hvac_action(self):
"""Return the current running hvac operation if supported.
Need to be one of CURRENT_HVAC_*.
Need to be one of HVACAction.*
"""
if "work_state" in self._device:
if self._device["work_state"] == "Heat":
return CURRENT_HVAC_HEAT
return HVACAction.HEATING
elif self._device["work_state"] == "NoHeat":
return CURRENT_HVAC_IDLE
return HVACAction.IDLE

@property
def temperature_unit(self):
"""Return the unit of measurement used by the platform."""
return TEMP_CELSIUS
return UnitOfTemperature.CELSIUS

@property
def target_temperature_step(self):
Expand All @@ -274,9 +272,9 @@ def set_temperature(self, **kwargs):
) # Preset_mode sent from action
elif ATTR_HVAC_MODE in kwargs:
value = kwargs.get(ATTR_HVAC_MODE) # HVAC_mode sent from action
if value == HVAC_MODE_AUTO:
if value == HVACMode.AUTO:
setpoint_code = self.get_setpoint_code_for_mode("at_home")
if value == HVAC_MODE_HEAT:
if value == HVACMode.HEAT:
setpoint_code = self.get_setpoint_code_for_mode("manual")
else:
setpoint_code = self.get_setpoint_code_for_mode(
Expand Down Expand Up @@ -409,9 +407,9 @@ def set_hvac_mode(self, hvac_mode):

_LOGGER.debug("Setting hvac mode to %s", hvac_mode)

if hvac_mode == HVAC_MODE_AUTO:
if hvac_mode == HVACMode.AUTO:
mode = "at_home" # We have to choose either at_home or leaving_home
elif hvac_mode == HVAC_MODE_HEAT:
elif hvac_mode == HVACMode.HEAT:
mode = "manual"

if mode is None:
Expand Down Expand Up @@ -491,13 +489,13 @@ def __init__(
@property
def hvac_action(self):
"""Return the current running hvac operation if supported.
Need to be one of CURRENT_HVAC_*.
Need to be one of HVACAction.*
"""
if "work_state" in self._device:
if self._device["work_state"] == "heat_active":
return CURRENT_HVAC_HEAT
return HVACAction.HEATING
elif self._device["work_state"] == "Heat":
return CURRENT_HVAC_IDLE
return HVACAction.IDLE


async def async_setup_entry(
Expand Down Expand Up @@ -561,7 +559,7 @@ def create_climate_entity(ally, name: str, device_id: str, model: str) -> AllyCl
support_flags = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
)
supported_hvac_modes = [HVAC_MODE_AUTO, HVAC_MODE_HEAT]
supported_hvac_modes = [HVACMode.AUTO, HVACMode.HEAT]
heat_min_temp = 4.5
heat_max_temp = 35.0
heat_step = 0.5
Expand Down
12 changes: 4 additions & 8 deletions custom_components/danfoss_ally/const.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
"""Danfoss_ally consts."""
from homeassistant.components.climate.const import (
HVAC_MODE_AUTO,
HVAC_MODE_HEAT,
HVAC_MODE_OFF,
)
from homeassistant.components.climate.const import HVACMode

THERMOSTAT_MODE_AUTO = "hot"
THERMOSTAT_MODE_MANUAL = "manual"
Expand All @@ -17,9 +13,9 @@
PRESET_HOLIDAY_HOME = "Holiday (Home)"

HA_TO_DANFOSS_HVAC_MODE_MAP = {
HVAC_MODE_OFF: THERMOSTAT_MODE_OFF,
HVAC_MODE_HEAT: THERMOSTAT_MODE_MANUAL,
HVAC_MODE_AUTO: THERMOSTAT_MODE_AUTO,
HVACMode.OFF: THERMOSTAT_MODE_OFF,
HVACMode.HEAT: THERMOSTAT_MODE_MANUAL,
HVACMode.AUTO: THERMOSTAT_MODE_AUTO,
}

DANFOSS_TO_HA_HVAC_MODE_MAP = {
Expand Down
8 changes: 4 additions & 4 deletions custom_components/danfoss_ally/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS
from homeassistant.const import PERCENTAGE, UnitOfTemperature
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import EntityCategory
Expand Down Expand Up @@ -41,7 +41,7 @@ class AllySensorType(IntEnum):
key=AllySensorType.TEMPERATURE,
device_class=SensorDeviceClass.TEMPERATURE,
entity_category=None,
native_unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
state_class=SensorStateClass.MEASUREMENT,
name="{} temperature",
),
Expand All @@ -65,7 +65,7 @@ class AllySensorType(IntEnum):
key=AllySensorType.FLOOR_TEMPERATURE,
device_class=SensorDeviceClass.TEMPERATURE,
entity_category=None,
native_unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
state_class=SensorStateClass.MEASUREMENT,
name="{} floor temperature",
),
Expand All @@ -88,7 +88,7 @@ class AllySensorType(IntEnum):
key=AllySensorType.EXTERNAL_SENSOR_TEMPERATURE,
device_class=SensorDeviceClass.TEMPERATURE,
entity_category=None,
native_unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
state_class=SensorStateClass.MEASUREMENT,
name="{} external sensor temperature",
entity_registry_enabled_default=False,
Expand Down

0 comments on commit 642d3b8

Please sign in to comment.