Skip to content

Commit

Permalink
Merge pull request #181 from jheling/jhe/depricated
Browse files Browse the repository at this point in the history
fix deprecated constants
  • Loading branch information
jheling authored Mar 28, 2024
2 parents 5a73ca1 + c4d57e6 commit e382111
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 34 deletions.
26 changes: 12 additions & 14 deletions custom_components/freeathome/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import voluptuous as vol

from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate.const import (HVAC_MODE_HEAT_COOL, HVAC_MODE_OFF,
SUPPORT_PRESET_MODE,
SUPPORT_TARGET_TEMPERATURE)
from homeassistant.const import (ATTR_TEMPERATURE, TEMP_CELSIUS)
from homeassistant.components.climate.const import (HVACMode, ClimateEntityFeature)
from homeassistant.const import (ATTR_TEMPERATURE, UnitOfTemperature)
from homeassistant.helpers import config_validation as cv, entity_platform, service

from .const import DOMAIN
Expand Down Expand Up @@ -123,14 +121,14 @@ def current_actuator(self):
@property
def target_temperature(self):
"""Return the temperature we try to reach."""
if self.hvac_mode == HVAC_MODE_OFF:
if self.hvac_mode == HVACMode.OFF:
return None
return float(self.thermostat_device.target_temperature)

@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 @@ -139,19 +137,19 @@ def target_temperature_step(self):
@property
def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
return ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE

@property
def hvac_mode(self):
if not self.thermostat_device.state:
return HVAC_MODE_OFF
return HVACMode.OFF
else:
return HVAC_MODE_HEAT_COOL
return HVACMode.HEAT_COOL

@property
def hvac_modes(self):
"""Return the list of available hvac operation modes."""
return [HVAC_MODE_HEAT_COOL, HVAC_MODE_OFF]
return [HVACMode.HEAT_COOL, HVACMode.OFF]

@property
def preset_modes(self):
Expand All @@ -168,9 +166,9 @@ def preset_mode(self):
def state(self):
"""Return current operation ie. heat, cool, idle."""
if not self.thermostat_device.state:
return HVAC_MODE_OFF
return HVACMode.OFF
else:
return HVAC_MODE_HEAT_COOL
return HVACMode.HEAT_COOL

@property
def icon(self):
Expand All @@ -187,10 +185,10 @@ async def after_update_callback(device):

async def async_set_hvac_mode(self, hvac_mode):
"""Set new target operation mode."""
if hvac_mode == HVAC_MODE_HEAT_COOL:
if hvac_mode == HVACMode.HEAT_COOL:
await self.thermostat_device.turn_on()

if hvac_mode == HVAC_MODE_OFF:
if hvac_mode == HVACMode.OFF:
await self.thermostat_device.turn_off()

async def async_set_preset_mode(self, preset_mode):
Expand Down
17 changes: 7 additions & 10 deletions custom_components/freeathome/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
import voluptuous as vol
from homeassistant.components.cover import (
CoverEntity,
CoverEntityFeature,
ATTR_POSITION,
ATTR_TILT_POSITION,
SUPPORT_CLOSE,
SUPPORT_OPEN,
SUPPORT_SET_POSITION,
SUPPORT_SET_TILT_POSITION,
SUPPORT_STOP
)
from homeassistant.helpers import config_validation as cv, entity_platform, service

Expand Down Expand Up @@ -52,18 +48,19 @@ def __init__(self, device):
self._state = self.cover_device.state

@property
def supported_features(self):
def supported_features(self) -> CoverEntityFeature:
"""Flag supported features (open and close are always supported)"""
supported_features = SUPPORT_OPEN | SUPPORT_CLOSE
supported_features = CoverEntityFeature(0)
supported_features = (CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE)

if self.cover_device.supports_stop():
supported_features |= SUPPORT_STOP
supported_features |= CoverEntityFeature.STOP

if self.cover_device.supports_position():
supported_features |= SUPPORT_SET_POSITION
supported_features |= CoverEntityFeature.SET_POSITION

if self.cover_device.supports_tilt_position():
supported_features |= SUPPORT_SET_TILT_POSITION
supported_features |= CoverEntityFeature.SET_TILT_POSITION

return supported_features

Expand Down
17 changes: 12 additions & 5 deletions custom_components/freeathome/light.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""" Support for Free@Home lights dimmers """
import logging
from homeassistant.components.light import (
ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, LightEntity)
ATTR_BRIGHTNESS, ColorMode, LightEntity)

from .const import DOMAIN

Expand Down Expand Up @@ -62,11 +62,18 @@ def should_poll(self):
return False

@property
def supported_features(self):
"""Flag supported features."""
def color_mode(self) -> str | None:
"""Return the color mode of the light."""
if self._is_dimmer:
return SUPPORT_BRIGHTNESS
return 0
return ColorMode.BRIGHTNESS
return ColorMode.ONOFF

@property
def supported_color_modes(self) -> set[str] | None:
"""Flag supported color modes."""
if self._is_dimmer:
return {ColorMode.BRIGHTNESS}
return {ColorMode.ONOFF}

@property
def is_on(self):
Expand Down
10 changes: 5 additions & 5 deletions custom_components/freeathome/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from homeassistant.components.sensor import SensorDeviceClass
from homeassistant.const import (
SPEED_KILOMETERS_PER_HOUR,
TEMP_CELSIUS,
UnitOfSpeed,
UnitOfTemperature,
PERCENTAGE,
CONCENTRATION_PARTS_PER_MILLION,
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
Expand All @@ -18,13 +18,13 @@
SENSOR_TYPES = {
"temperature": [
"Temperature",
TEMP_CELSIUS,
UnitOfTemperature.CELSIUS,
"mdi:thermometer",
SensorDeviceClass.TEMPERATURE,
],
"windstrength": [
"Wind Strength",
SPEED_KILOMETERS_PER_HOUR,
UnitOfSpeed.KILOMETERS_PER_HOUR,
"mdi:weather-windy",
None,
],
Expand Down Expand Up @@ -141,7 +141,7 @@ def __init__(self, device: FahDevice):
@property
def state(self):
"""Return the state of the device."""
if self._unit_of_measurement == SPEED_KILOMETERS_PER_HOUR:
if self._unit_of_measurement == UnitOfSpeed.KILOMETERS_PER_HOUR:
return ("%.2f" % (float(self._state) * 3.6))
else:
return self._state
Expand Down

0 comments on commit e382111

Please sign in to comment.