Skip to content

Commit

Permalink
Adds support for Home Assistant 2024.x (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
dotvezz authored Jan 10, 2024
1 parent 6c85dae commit 5c98df2
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 55 deletions.
4 changes: 2 additions & 2 deletions custom_components/dyson_local/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .vendor.libdyson import Dyson360Eye, Dyson360Heurist, DysonPureHotCoolLink

from homeassistant.components.binary_sensor import (
DEVICE_CLASS_BATTERY_CHARGING,
BinarySensorDeviceClass,
BinarySensorEntity,
)
from homeassistant.config_entries import ConfigEntry
Expand Down Expand Up @@ -53,7 +53,7 @@ def is_on(self) -> bool:
@property
def device_class(self) -> str:
"""Return the device class of the sensor."""
return DEVICE_CLASS_BATTERY_CHARGING
return BinarySensorDeviceClass.BATTERY_CHARGING

@property
def sub_name(self) -> str:
Expand Down
43 changes: 19 additions & 24 deletions custom_components/dyson_local/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,25 @@

from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate.const import (
CURRENT_HVAC_COOL,
CURRENT_HVAC_HEAT,
CURRENT_HVAC_IDLE,
CURRENT_HVAC_OFF,
HVACAction,
FAN_DIFFUSE,
FAN_FOCUS,
HVAC_MODE_COOL,
HVAC_MODE_HEAT,
HVAC_MODE_OFF,
SUPPORT_FAN_MODE,
SUPPORT_TARGET_TEMPERATURE,
HVACMode,
ClimateEntityFeature
)

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, CONF_NAME, TEMP_CELSIUS
from homeassistant.const import ATTR_TEMPERATURE, CONF_NAME, UnitOfTemperature
from homeassistant.core import Callable, HomeAssistant

from . import DysonEntity

_LOGGER = logging.getLogger(__name__)

HVAC_MODES = [HVAC_MODE_OFF, HVAC_MODE_COOL, HVAC_MODE_HEAT]
HVAC_MODES = [HVACMode.OFF, HVACMode.COOL, HVACMode.HEAT]
FAN_MODES = [FAN_FOCUS, FAN_DIFFUSE]
SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE
SUPPORT_FLAGS_LINK = SUPPORT_FLAGS | SUPPORT_FAN_MODE
SUPPORT_FLAGS = ClimateEntityFeature.TARGET_TEMPERATURE
SUPPORT_FLAGS_LINK = SUPPORT_FLAGS | ClimateEntityFeature.FAN_MODE


async def async_setup_entry(
Expand All @@ -55,10 +50,10 @@ class DysonClimateEntity(DysonEntity, ClimateEntity):
def hvac_mode(self) -> str:
"""Return hvac operation."""
if not self._device.is_on:
return HVAC_MODE_OFF
return HVACMode.OFF
if self._device.heat_mode_is_on:
return HVAC_MODE_HEAT
return HVAC_MODE_COOL
return HVACMode.HEAT
return HVACMode.COOL

@property
def hvac_modes(self) -> List[str]:
Expand All @@ -69,12 +64,12 @@ def hvac_modes(self) -> List[str]:
def hvac_action(self) -> str:
"""Return the current running hvac operation."""
if not self._device.is_on:
return CURRENT_HVAC_OFF
return HVACAction.OFF
if self._device.heat_mode_is_on:
if self._device.heat_status_is_on:
return CURRENT_HVAC_HEAT
return CURRENT_HVAC_IDLE
return CURRENT_HVAC_COOL
return HVACAction.HEAT
return HVACAction.IDLE
return HVACAction.COOL

@property
def supported_features(self) -> int:
Expand All @@ -84,7 +79,7 @@ def supported_features(self) -> int:
@property
def temperature_unit(self) -> str:
"""Return the unit of measurement."""
return TEMP_CELSIUS
return UnitOfTemperature.CELSIUS

@property
def target_temperature(self) -> int:
Expand Down Expand Up @@ -134,13 +129,13 @@ def set_temperature(self, **kwargs):
def set_hvac_mode(self, hvac_mode: str):
"""Set new hvac mode."""
_LOGGER.debug("Set %s heat mode %s", self.name, hvac_mode)
if hvac_mode == HVAC_MODE_OFF:
if hvac_mode == HVACMode.OFF:
self._device.turn_off()
elif not self._device.is_on:
self._device.turn_on()
if hvac_mode == HVAC_MODE_HEAT:
if hvac_mode == HVACMode.HEAT:
self._device.enable_heat_mode()
elif hvac_mode == HVAC_MODE_COOL:
elif hvac_mode == HVACMode.COOL:
self._device.disable_heat_mode()


Expand Down
11 changes: 4 additions & 7 deletions custom_components/dyson_local/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
from homeassistant.components.fan import (
DIRECTION_FORWARD,
DIRECTION_REVERSE,
SUPPORT_DIRECTION,
SUPPORT_OSCILLATE,
SUPPORT_PRESET_MODE,
SUPPORT_SET_SPEED,
FanEntityFeature,
FanEntity,
NotValidPresetModeError,
)
Expand Down Expand Up @@ -55,7 +52,7 @@

SPEED_RANGE = (1, 10)

COMMON_FEATURES = SUPPORT_OSCILLATE | SUPPORT_SET_SPEED | SUPPORT_PRESET_MODE
COMMON_FEATURES = FanEntityFeature.OSCILLATE | FanEntityFeature.SET_SPEED | FanEntityFeature.PRESET_MODE


async def async_setup_entry(
Expand Down Expand Up @@ -199,7 +196,7 @@ class DysonPureCoolEntity(DysonFanEntity):
@property
def supported_features(self) -> int:
"""Flag supported features."""
return COMMON_FEATURES | SUPPORT_DIRECTION
return COMMON_FEATURES | FanEntityFeature.DIRECTION

@property
def current_direction(self) -> str:
Expand Down Expand Up @@ -253,7 +250,7 @@ class DysonPurifierHumidifyCoolEntity(DysonFanEntity):
@property
def supported_features(self) -> int:
"""Flag supported features."""
return COMMON_FEATURES | SUPPORT_DIRECTION
return COMMON_FEATURES | FanEntityFeature.DIRECTION

@property
def current_direction(self) -> str:
Expand Down
6 changes: 3 additions & 3 deletions custom_components/dyson_local/humidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from homeassistant.components.humidifier import (
DEVICE_CLASS_HUMIDIFIER,
SUPPORT_MODES,
HumidifierEntityFeature,
HumidifierEntity,
)
from homeassistant.components.humidifier.const import MODE_AUTO, MODE_NORMAL
Expand All @@ -19,7 +19,7 @@

AVAILABLE_MODES = [MODE_NORMAL, MODE_AUTO]

SUPPORTED_FEATURES = SUPPORT_MODES
SUPPORTED_FEATURES = HumidifierEntityFeature.MODES


async def async_setup_entry(
Expand All @@ -40,7 +40,7 @@ class DysonHumidifierEntity(DysonEntity, HumidifierEntity):
_attr_available_modes = AVAILABLE_MODES
_attr_max_humidity = 70
_attr_min_humidity = 30
_attr_supported_features = SUPPORT_MODES
_attr_supported_features = HumidifierEntityFeature.MODES

@property
def is_on(self) -> bool:
Expand Down
11 changes: 6 additions & 5 deletions custom_components/dyson_local/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
CONCENTRATION_PARTS_PER_MILLION,
CONF_NAME,
PERCENTAGE,
TEMP_CELSIUS,
TIME_HOURS,
UnitOfTemperature,
UnitOfTime,
)

from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.update_coordinator import (
Expand Down Expand Up @@ -144,7 +145,7 @@ class DysonFilterLifeSensor(DysonSensor):
_SENSOR_NAME = "Filter Life"
_attr_entity_category = EntityCategory.DIAGNOSTIC
_attr_icon = "mdi:filter-outline"
_attr_native_unit_of_measurement = TIME_HOURS
_attr_native_unit_of_measurement = UnitOfTime.HOURS

@property
def native_value(self) -> int:
Expand Down Expand Up @@ -204,7 +205,7 @@ class DysonNextDeepCleanSensor(DysonSensor):
_SENSOR_NAME = "Next Deep Clean"
_attr_entity_category = EntityCategory.DIAGNOSTIC
_attr_icon = "mdi:filter-outline"
_attr_native_unit_of_measurement = TIME_HOURS
_attr_native_unit_of_measurement = UnitOfTime.HOURS

@property
def native_value(self) -> Optional[int]:
Expand Down Expand Up @@ -246,7 +247,7 @@ class DysonTemperatureSensor(DysonSensorEnvironmental):
_SENSOR_TYPE = "temperature"
_SENSOR_NAME = "Temperature"
_attr_device_class = SensorDeviceClass.TEMPERATURE
_attr_native_unit_of_measurement = TEMP_CELSIUS
_attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
_attr_state_class = SensorStateClass.MEASUREMENT

@property
Expand Down
22 changes: 8 additions & 14 deletions custom_components/dyson_local/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@
STATE_DOCKED,
STATE_ERROR,
STATE_RETURNING,
SUPPORT_BATTERY,
SUPPORT_FAN_SPEED,
SUPPORT_PAUSE,
SUPPORT_RETURN_HOME,
SUPPORT_START,
SUPPORT_STATE,
SUPPORT_STATUS,
VacuumEntityFeature,
StateVacuumEntity,
)
from homeassistant.config_entries import ConfigEntry
Expand All @@ -32,13 +26,13 @@
from .const import DATA_DEVICES, DOMAIN

SUPPORTED_FEATURES = (
SUPPORT_START
| SUPPORT_PAUSE
| SUPPORT_RETURN_HOME
| SUPPORT_FAN_SPEED
| SUPPORT_STATUS
| SUPPORT_STATE
| SUPPORT_BATTERY
VacuumEntityFeature.START
| VacuumEntityFeature.PAUSE
| VacuumEntityFeature.RETURN_HOME
| VacuumEntityFeature.FAN_SPEED
| VacuumEntityFeature.STATUS
| VacuumEntityFeature.STATE
| VacuumEntityFeature.BATTERY
)

DYSON_STATUS = {
Expand Down

0 comments on commit 5c98df2

Please sign in to comment.