diff --git a/custom_components/dyson_local/binary_sensor.py b/custom_components/dyson_local/binary_sensor.py index 19d5106..72c0073 100644 --- a/custom_components/dyson_local/binary_sensor.py +++ b/custom_components/dyson_local/binary_sensor.py @@ -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 @@ -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: diff --git a/custom_components/dyson_local/climate.py b/custom_components/dyson_local/climate.py index 534e243..8ed6a42 100644 --- a/custom_components/dyson_local/climate.py +++ b/custom_components/dyson_local/climate.py @@ -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( @@ -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]: @@ -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: @@ -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: @@ -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() diff --git a/custom_components/dyson_local/fan.py b/custom_components/dyson_local/fan.py index 94f52ab..7bb3a27 100644 --- a/custom_components/dyson_local/fan.py +++ b/custom_components/dyson_local/fan.py @@ -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, ) @@ -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( @@ -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: @@ -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: diff --git a/custom_components/dyson_local/humidifier.py b/custom_components/dyson_local/humidifier.py index e623251..e464cb6 100644 --- a/custom_components/dyson_local/humidifier.py +++ b/custom_components/dyson_local/humidifier.py @@ -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 @@ -19,7 +19,7 @@ AVAILABLE_MODES = [MODE_NORMAL, MODE_AUTO] -SUPPORTED_FEATURES = SUPPORT_MODES +SUPPORTED_FEATURES = HumidifierEntityFeature.MODES async def async_setup_entry( @@ -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: diff --git a/custom_components/dyson_local/sensor.py b/custom_components/dyson_local/sensor.py index d56584c..8c8e8d2 100644 --- a/custom_components/dyson_local/sensor.py +++ b/custom_components/dyson_local/sensor.py @@ -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 ( @@ -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: @@ -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]: @@ -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 diff --git a/custom_components/dyson_local/vacuum.py b/custom_components/dyson_local/vacuum.py index 24dc1f8..289cbe0 100644 --- a/custom_components/dyson_local/vacuum.py +++ b/custom_components/dyson_local/vacuum.py @@ -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 @@ -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 = {