diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1faee7f..36140ee 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,19 +21,19 @@ repos: - id: check-yaml - id: detect-private-key - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.0 + rev: v0.8.3 hooks: - id: ruff args: - --fix - id: ruff-format - repo: https://github.com/commitizen-tools/commitizen - rev: v3.31.0 + rev: v4.1.0 hooks: - id: commitizen stages: [commit-msg] - repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook - rev: v9.18.0 + rev: v9.20.0 hooks: - id: commitlint stages: [commit-msg] diff --git a/custom_components/midea_ac_lan/__init__.py b/custom_components/midea_ac_lan/__init__.py index a6517e3..fd98050 100644 --- a/custom_components/midea_ac_lan/__init__.py +++ b/custom_components/midea_ac_lan/__init__.py @@ -63,7 +63,7 @@ async def update_listener(hass: HomeAssistant, config_entry: ConfigEntry) -> Non hass.async_create_task( hass.config_entries.async_forward_entry_setups(config_entry, ALL_PLATFORM), ) - device_id: int = cast(int, config_entry.data.get(CONF_DEVICE_ID)) + device_id: int = cast("int", config_entry.data.get(CONF_DEVICE_ID)) customize = config_entry.options.get(CONF_CUSTOMIZE, "") ip_address = config_entry.options.get(CONF_IP_ADDRESS, None) refresh_interval = config_entry.options.get(CONF_REFRESH_INTERVAL, None) @@ -88,7 +88,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa: attributes = [] for device_entities in MIDEA_DEVICES.values(): for attribute_name, attribute in cast( - dict, + "dict", device_entities["entities"], ).items(): if ( @@ -108,7 +108,7 @@ def service_set_attribute(service: Any) -> None: # noqa: ANN401 value = 102 item = None if _dev := MIDEA_DEVICES.get(dev.device_type): - item = cast(dict, _dev["entities"]).get(attr) + item = cast("dict", _dev["entities"]).get(attr) if ( item and (item.get("type") in EXTRA_SWITCH) diff --git a/custom_components/midea_ac_lan/binary_sensor.py b/custom_components/midea_ac_lan/binary_sensor.py index 522b57f..f956d4d 100644 --- a/custom_components/midea_ac_lan/binary_sensor.py +++ b/custom_components/midea_ac_lan/binary_sensor.py @@ -27,7 +27,7 @@ async def async_setup_entry( extra_sensors = config_entry.options.get(CONF_SENSORS, []) binary_sensors = [] for entity_key, config in cast( - dict, + "dict", MIDEA_DEVICES[device.device_type]["entities"], ).items(): if config["type"] == Platform.BINARY_SENSOR and entity_key in extra_sensors: @@ -42,9 +42,9 @@ class MideaBinarySensor(MideaEntity, BinarySensorEntity): @property def device_class(self) -> BinarySensorDeviceClass | None: """Return device class.""" - return cast(BinarySensorDeviceClass, self._config.get("device_class")) + return cast("BinarySensorDeviceClass", self._config.get("device_class")) @property def is_on(self) -> bool: """Return true if sensor state is on.""" - return cast(bool, self._device.get_attribute(self._entity_key)) + return cast("bool", self._device.get_attribute(self._entity_key)) diff --git a/custom_components/midea_ac_lan/climate.py b/custom_components/midea_ac_lan/climate.py index 8e4c254..4fd477f 100644 --- a/custom_components/midea_ac_lan/climate.py +++ b/custom_components/midea_ac_lan/climate.py @@ -81,7 +81,7 @@ async def async_setup_entry( | MideaFBClimate ] = [] for entity_key, config in cast( - dict, + "dict", MIDEA_DEVICES[device.device_type]["entities"], ).items(): if config["type"] == Platform.CLIMATE and ( @@ -142,19 +142,19 @@ def supported_features(self) -> ClimateEntityFeature: def hvac_mode(self) -> HVACMode: """Midea Climate hvac mode.""" if self._device.get_attribute("power"): - mode = cast(int, self._device.get_attribute("mode")) + mode = cast("int", self._device.get_attribute("mode")) return self.hvac_modes[mode] return HVACMode.OFF @property def target_temperature(self) -> float: """Midea Climate target temperature.""" - return cast(float, self._device.get_attribute("target_temperature")) + return cast("float", self._device.get_attribute("target_temperature")) @property def current_temperature(self) -> float | None: """Midea Climate current temperature.""" - return cast(float | None, self._device.get_attribute("indoor_temperature")) + return cast("float | None", self._device.get_attribute("indoor_temperature")) @property def preset_mode(self) -> str: @@ -176,7 +176,7 @@ def preset_mode(self) -> str: @property def extra_state_attributes(self) -> dict: """Midea Climate extra state attributes.""" - return cast(dict, self._device.attributes) + return cast("dict", self._device.attributes) def turn_on(self, **kwargs: Any) -> None: # noqa: ANN401, ARG002 """Midea Climate turn on.""" @@ -290,7 +290,7 @@ def __init__(self, device: MideaACDevice, entity_key: str) -> None: @property def fan_mode(self) -> str: """Midea AC Climate fan mode.""" - fan_speed = cast(int, self._device.get_attribute(ACAttributes.fan_speed)) + fan_speed = cast("int", self._device.get_attribute(ACAttributes.fan_speed)) if fan_speed > FanSpeed.AUTO: return str(FAN_AUTO) if fan_speed > FanSpeed.FULL_SPEED: @@ -321,12 +321,15 @@ def swing_mode(self) -> str: @property def current_humidity(self) -> float | None: """Midea Climate current humidity.""" - return cast(float | None, self._device.get_attribute("indoor_humidity")) + return cast("float | None", self._device.get_attribute("indoor_humidity")) @property def outdoor_temperature(self) -> float: """Midea AC Climate outdoor temperature.""" - return cast(float, self._device.get_attribute(ACAttributes.outdoor_temperature)) + return cast( + "float", + self._device.get_attribute(ACAttributes.outdoor_temperature), + ) def set_fan_mode(self, fan_mode: str) -> None: """Midea AC Climate set fan mode.""" @@ -367,18 +370,18 @@ def __init__(self, device: MideaCCDevice, entity_key: str) -> None: @property def fan_modes(self) -> list[str] | None: """Midea CC Climate fan modes.""" - return cast(list, self._device.fan_modes) + return cast("list", self._device.fan_modes) @property def fan_mode(self) -> str: """Midea CC Climate fan mode.""" - return cast(str, self._device.get_attribute(CCAttributes.fan_speed)) + return cast("str", self._device.get_attribute(CCAttributes.fan_speed)) @property def target_temperature_step(self) -> float: """Midea CC Climate target temperature step.""" return cast( - float, + "float", self._device.get_attribute(CCAttributes.temperature_precision), ) @@ -429,27 +432,30 @@ def supported_features(self) -> ClimateEntityFeature: @property def min_temp(self) -> float: """Midea CF Climate min temperature.""" - return cast(float, self._device.get_attribute(CFAttributes.min_temperature)) + return cast("float", self._device.get_attribute(CFAttributes.min_temperature)) @property def max_temp(self) -> float: """Midea CF Climate max temperature.""" - return cast(float, self._device.get_attribute(CFAttributes.max_temperature)) + return cast("float", self._device.get_attribute(CFAttributes.max_temperature)) @property def target_temperature_low(self) -> float: """Midea CF Climate target temperature.""" - return cast(float, self._device.get_attribute(CFAttributes.min_temperature)) + return cast("float", self._device.get_attribute(CFAttributes.min_temperature)) @property def target_temperature_high(self) -> float: """Midea CF Climate target temperature high.""" - return cast(float, self._device.get_attribute(CFAttributes.max_temperature)) + return cast("float", self._device.get_attribute(CFAttributes.max_temperature)) @property def current_temperature(self) -> float: """Midea CF Climate current temperature.""" - return cast(float, self._device.get_attribute(CFAttributes.current_temperature)) + return cast( + "float", + self._device.get_attribute(CFAttributes.current_temperature), + ) class MideaC3Climate(MideaClimate): @@ -487,7 +493,7 @@ def _temperature(self, minimum: bool) -> list[str]: if minimum else C3Attributes.temperature_max) # fmt: on - return cast(list[str], self._device.get_attribute(value)) + return cast("list[str]", self._device.get_attribute(value)) @property def supported_features(self) -> ClimateEntityFeature: @@ -501,7 +507,7 @@ def supported_features(self) -> ClimateEntityFeature: def target_temperature_step(self) -> float: """Midea C3 Climate target temperature step.""" zone_temp_type = cast( - list[str], + "list[str]", self._device.get_attribute(C3Attributes.zone_temp_type), ) return float( @@ -512,7 +518,7 @@ def target_temperature_step(self) -> float: def min_temp(self) -> float: """Midea C3 Climate min temperature.""" return cast( - float, + "float", self._temperature(True)[self._zone], ) @@ -520,7 +526,7 @@ def min_temp(self) -> float: def max_temp(self) -> float: """Midea C3 Climate max temperature.""" return cast( - float, + "float", self._temperature(False)[self._zone], ) @@ -528,7 +534,7 @@ def max_temp(self) -> float: def target_temperature_low(self) -> float: """Midea C3 Climate target temperature low.""" return cast( - float, + "float", self._temperature(True)[self._zone], ) @@ -536,7 +542,7 @@ def target_temperature_low(self) -> float: def target_temperature_high(self) -> float: """Midea C3 Climate target temperature high.""" return cast( - float, + "float", self._temperature(False)[self._zone], ) @@ -560,11 +566,11 @@ def hvac_mode(self) -> HVACMode: def target_temperature(self) -> float: """Midea C3 Climate target temperature.""" target_temperature = cast( - list[str], + "list[str]", self._device.get_attribute(C3Attributes.target_temperature), ) return cast( - float, + "float", target_temperature[self._zone], ) @@ -630,7 +636,7 @@ def supported_features(self) -> ClimateEntityFeature: @property def preset_mode(self) -> str: """Midea FB Climate preset mode.""" - return cast(str, self._device.get_attribute(attr=FBAttributes.mode)) + return cast("str", self._device.get_attribute(attr=FBAttributes.mode)) @property def hvac_mode(self) -> HVACMode: @@ -644,7 +650,10 @@ def hvac_mode(self) -> HVACMode: @property def current_temperature(self) -> float: """Midea FB Climate current temperature.""" - return cast(float, self._device.get_attribute(FBAttributes.current_temperature)) + return cast( + "float", + self._device.get_attribute(FBAttributes.current_temperature), + ) def set_temperature(self, **kwargs: Any) -> None: # noqa: ANN401 """Midea FB Climate set temperature.""" diff --git a/custom_components/midea_ac_lan/config_flow.py b/custom_components/midea_ac_lan/config_flow.py index b11a901..a804376 100644 --- a/custom_components/midea_ac_lan/config_flow.py +++ b/custom_components/midea_ac_lan/config_flow.py @@ -934,8 +934,8 @@ async def async_step_init( sensors = {} switches = {} for attribute, attribute_config in cast( - dict, - MIDEA_DEVICES[cast(int, self._device_type)]["entities"], + "dict", + MIDEA_DEVICES[cast("int", self._device_type)]["entities"], ).items(): attribute_name = ( attribute if isinstance(attribute, str) else attribute.value diff --git a/custom_components/midea_ac_lan/fan.py b/custom_components/midea_ac_lan/fan.py index be6166d..83a1458 100644 --- a/custom_components/midea_ac_lan/fan.py +++ b/custom_components/midea_ac_lan/fan.py @@ -42,7 +42,7 @@ async def async_setup_entry( MideaFAFan | MideaB6Fan | MideaACFreshAirFan | MideaCEFan | MideaX40Fan ] = [] for entity_key, config in cast( - dict, + "dict", MIDEA_DEVICES[device.device_type]["entities"], ).items(): if config["type"] == Platform.FAN and ( @@ -83,22 +83,22 @@ def preset_modes(self) -> list[str] | None: @property def is_on(self) -> bool: """Midea Fan is on.""" - return cast(bool, self._device.get_attribute("power")) + return cast("bool", self._device.get_attribute("power")) @property def oscillating(self) -> bool: """Midea Fan oscillating.""" - return cast(bool, self._device.get_attribute("oscillate")) + return cast("bool", self._device.get_attribute("oscillate")) @property def preset_mode(self) -> str | None: """Midea Fan preset mode.""" - return cast(str, self._device.get_attribute("mode")) + return cast("str", self._device.get_attribute("mode")) @property def fan_speed(self) -> int | None: """Midea Fan fan speed.""" - return cast(int, self._device.get_attribute("fan_speed")) + return cast("int", self._device.get_attribute("fan_speed")) def turn_off(self, **kwargs: Any) -> None: # noqa: ANN401, ARG002 """Midea Fan turn off.""" @@ -117,7 +117,7 @@ def percentage(self) -> int | None: """Midea Fan percentage.""" if not self.fan_speed: return None - return int(round(self.fan_speed * self.percentage_step)) + return int(round(self.fan_speed * self.percentage_step)) # noqa: RUF046 def set_percentage(self, percentage: int) -> None: """Midea Fan set percentage.""" @@ -209,17 +209,17 @@ def __init__(self, device: MideaACDevice, entity_key: str) -> None: @property def preset_modes(self) -> list[str] | None: """Midea AC Fan preset modes.""" - return cast(list, self._device.fresh_air_fan_speeds) + return cast("list", self._device.fresh_air_fan_speeds) @property def is_on(self) -> bool: """Midea AC Fan is on.""" - return cast(bool, self._device.get_attribute(ACAttributes.fresh_air_power)) + return cast("bool", self._device.get_attribute(ACAttributes.fresh_air_power)) @property def fan_speed(self) -> int: """Midea AC Fan fan speed.""" - return cast(int, self._device.get_attribute(ACAttributes.fresh_air_fan_speed)) + return cast("int", self._device.get_attribute(ACAttributes.fresh_air_fan_speed)) def turn_on( self, @@ -249,7 +249,7 @@ def set_preset_mode(self, preset_mode: str) -> None: @property def preset_mode(self) -> str | None: """Midea AC Fan preset mode.""" - return cast(str, self._device.get_attribute(attr=ACAttributes.fresh_air_mode)) + return cast("str", self._device.get_attribute(attr=ACAttributes.fresh_air_mode)) class MideaCEFan(MideaFan): @@ -299,7 +299,7 @@ def __init__(self, device: MideaX40Device, entity_key: str) -> None: @property def is_on(self) -> bool: """Midea X40 Fan is on.""" - return cast(int, self._device.get_attribute(attr=X40Attributes.fan_speed)) > 0 + return cast("int", self._device.get_attribute(attr=X40Attributes.fan_speed)) > 0 def turn_on( self, diff --git a/custom_components/midea_ac_lan/humidifier.py b/custom_components/midea_ac_lan/humidifier.py index d33059b..2c998a8 100644 --- a/custom_components/midea_ac_lan/humidifier.py +++ b/custom_components/midea_ac_lan/humidifier.py @@ -34,7 +34,7 @@ async def async_setup_entry( extra_switches = config_entry.options.get(CONF_SWITCHES, []) devs: list[MideaA1Humidifier | MideaFDHumidifier] = [] for entity_key, config in cast( - dict, + "dict", MIDEA_DEVICES[device.device_type]["entities"], ).items(): if config["type"] == Platform.HUMIDIFIER and ( @@ -62,22 +62,22 @@ def __init__(self, device: MideaHumidifierDevice, entity_key: str) -> None: @property def current_humidity(self) -> float | None: """Midea Humidifier current humidity.""" - return cast(float, self._device.get_attribute("current_humidity")) + return cast("float", self._device.get_attribute("current_humidity")) @property def target_humidity(self) -> float: """Midea Humidifier target humidity.""" - return cast(float, self._device.get_attribute("target_humidity")) + return cast("float", self._device.get_attribute("target_humidity")) @property def mode(self) -> str: """Midea Humidifier mode.""" - return cast(str, self._device.get_attribute("mode")) + return cast("str", self._device.get_attribute("mode")) @property def available_modes(self) -> list[str] | None: """Midea Humidifier available modes.""" - return cast(list, self._device.modes) + return cast("list", self._device.modes) def set_humidity(self, humidity: int) -> None: """Midea Humidifier set humidity.""" @@ -90,7 +90,7 @@ def set_mode(self, mode: str) -> None: @property def is_on(self) -> bool: """Midea Humidifier is on.""" - return cast(bool, self._device.get_attribute(attr="power")) + return cast("bool", self._device.get_attribute(attr="power")) def turn_on(self, **kwargs: Any) -> None: # noqa: ANN401, ARG002 """Midea Humidifier turn on.""" diff --git a/custom_components/midea_ac_lan/light.py b/custom_components/midea_ac_lan/light.py index 47c2541..8e66cd2 100644 --- a/custom_components/midea_ac_lan/light.py +++ b/custom_components/midea_ac_lan/light.py @@ -36,7 +36,7 @@ async def async_setup_entry( extra_switches = config_entry.options.get(CONF_SWITCHES, []) devs = [] for entity_key, config in cast( - dict, + "dict", MIDEA_DEVICES[device.device_type]["entities"], ).items(): if config["type"] == Platform.LIGHT and ( @@ -108,17 +108,17 @@ def _calc_color_mode(self, supported: set[ColorMode]) -> ColorMode: @property def is_on(self) -> bool: """Midea Light is on.""" - return cast(bool, self._device.get_attribute(X13Attributes.power)) + return cast("bool", self._device.get_attribute(X13Attributes.power)) @property def brightness(self) -> int | None: """Midea Light brightness.""" - return cast(int, self._device.get_attribute(X13Attributes.brightness)) + return cast("int", self._device.get_attribute(X13Attributes.brightness)) @property def rgb_color(self) -> tuple[int, int, int] | None: """Midea Light rgb color.""" - return cast(tuple, self._device.get_attribute(X13Attributes.rgb_color)) + return cast("tuple", self._device.get_attribute(X13Attributes.rgb_color)) @property def color_temp(self) -> int | None: @@ -130,7 +130,7 @@ def color_temp(self) -> int | None: @property def color_temp_kelvin(self) -> int | None: """Midea Light color temperature kelvin.""" - return cast(int, self._device.get_attribute(X13Attributes.color_temperature)) + return cast("int", self._device.get_attribute(X13Attributes.color_temperature)) @property def min_mireds(self) -> int: @@ -155,12 +155,12 @@ def max_color_temp_kelvin(self) -> int: @property def effect_list(self) -> list[str] | None: """Midea Light effect list.""" - return cast(list, self._device.effects) + return cast("list", self._device.effects) @property def effect(self) -> str | None: """Midea Light effect.""" - return cast(str, self._device.get_attribute(X13Attributes.effect)) + return cast("str", self._device.get_attribute(X13Attributes.effect)) def turn_on(self, **kwargs: Any) -> None: # noqa: ANN401 """Midea Light turn on.""" diff --git a/custom_components/midea_ac_lan/lock.py b/custom_components/midea_ac_lan/lock.py index 2c6110e..e66f974 100644 --- a/custom_components/midea_ac_lan/lock.py +++ b/custom_components/midea_ac_lan/lock.py @@ -24,7 +24,7 @@ async def async_setup_entry( extra_switches = config_entry.options.get(CONF_SWITCHES, []) locks = [] for entity_key, config in cast( - dict, + "dict", MIDEA_DEVICES[device.device_type]["entities"], ).items(): if config["type"] == Platform.LOCK and entity_key in extra_switches: @@ -39,7 +39,7 @@ class MideaLock(MideaEntity, LockEntity): @property def is_locked(self) -> bool: """Return true if state is locked.""" - return cast(bool, self._device.get_attribute(self._entity_key)) + return cast("bool", self._device.get_attribute(self._entity_key)) def lock(self, **kwargs: Any) -> None: # noqa: ANN401, ARG002 """Lock the lock.""" diff --git a/custom_components/midea_ac_lan/midea_entity.py b/custom_components/midea_ac_lan/midea_entity.py index 28ec3d5..dc0e3a0 100644 --- a/custom_components/midea_ac_lan/midea_entity.py +++ b/custom_components/midea_ac_lan/midea_entity.py @@ -28,9 +28,10 @@ def __init__(self, device: MideaDevice, entity_key: str) -> None: """Initialize Midea base entity.""" self._device = device self._device.register_update(self.update_state) - self._config = cast(dict, MIDEA_DEVICES[self._device.device_type]["entities"])[ - entity_key - ] + self._config = cast( + "dict", + MIDEA_DEVICES[self._device.device_type]["entities"], + )[entity_key] self._entity_key = entity_key self._unique_id = f"{DOMAIN}.{self._device.device_id}_{entity_key}" self.entity_id = self._unique_id @@ -84,7 +85,7 @@ def available(self) -> bool: @property def icon(self) -> str: """Return entity icon.""" - return cast(str, self._config.get("icon")) + return cast("str", self._config.get("icon")) @callback def update_state(self, status: Any) -> None: # noqa: ANN401 diff --git a/custom_components/midea_ac_lan/number.py b/custom_components/midea_ac_lan/number.py index e113b12..9a02165 100644 --- a/custom_components/midea_ac_lan/number.py +++ b/custom_components/midea_ac_lan/number.py @@ -25,7 +25,7 @@ async def async_setup_entry( extra_switches = config_entry.options.get(CONF_SWITCHES, []) numbers = [] for entity_key, config in cast( - dict, + "dict", MIDEA_DEVICES[device.device_type]["entities"], ).items(): if config["type"] == Platform.NUMBER and entity_key in extra_switches: @@ -48,7 +48,7 @@ def __init__(self, device: MideaDevice, entity_key: str) -> None: def native_min_value(self) -> float: """Return minimum value.""" return cast( - float, + "float", ( self._min_value if isinstance(self._min_value, int) @@ -64,7 +64,7 @@ def native_min_value(self) -> float: def native_max_value(self) -> float: """Return maximum value.""" return cast( - float, + "float", ( self._max_value if isinstance(self._max_value, int) @@ -80,7 +80,7 @@ def native_max_value(self) -> float: def native_step(self) -> float: """Return step value.""" return cast( - float, + "float", ( self._step_value if isinstance(self._step_value, int) @@ -95,7 +95,7 @@ def native_step(self) -> float: @property def native_value(self) -> float: """Return value.""" - return cast(float, self._device.get_attribute(self._entity_key)) + return cast("float", self._device.get_attribute(self._entity_key)) def set_native_value(self, value: Any) -> None: # noqa: ANN401 """Set value.""" diff --git a/custom_components/midea_ac_lan/select.py b/custom_components/midea_ac_lan/select.py index 38e765b..7672fe5 100644 --- a/custom_components/midea_ac_lan/select.py +++ b/custom_components/midea_ac_lan/select.py @@ -25,7 +25,7 @@ async def async_setup_entry( extra_switches = config_entry.options.get(CONF_SWITCHES, []) selects = [] for entity_key, config in cast( - dict, + "dict", MIDEA_DEVICES[device.device_type]["entities"], ).items(): if config["type"] == Platform.SELECT and entity_key in extra_switches: @@ -45,12 +45,12 @@ def __init__(self, device: MideaDevice, entity_key: str) -> None: @property def options(self) -> list[str]: """Return entity options.""" - return cast(list, getattr(self._device, self._options_name)) + return cast("list", getattr(self._device, self._options_name)) @property def current_option(self) -> str: """Return entity current option.""" - return cast(str, self._device.get_attribute(self._entity_key)) + return cast("str", self._device.get_attribute(self._entity_key)) def select_option(self, option: str) -> None: """Select entity option.""" diff --git a/custom_components/midea_ac_lan/sensor.py b/custom_components/midea_ac_lan/sensor.py index 7fe7b60..4d1db3f 100644 --- a/custom_components/midea_ac_lan/sensor.py +++ b/custom_components/midea_ac_lan/sensor.py @@ -29,7 +29,7 @@ async def async_setup_entry( extra_sensors = config_entry.options.get(CONF_SENSORS, []) sensors = [] for entity_key, config in cast( - dict, + "dict", MIDEA_DEVICES[device.device_type]["entities"], ).items(): if config["type"] == Platform.SENSOR and entity_key in extra_sensors: @@ -44,22 +44,22 @@ class MideaSensor(MideaEntity, SensorEntity): @property def native_value(self) -> StateType: """Return entity value.""" - return cast(StateType, self._device.get_attribute(self._entity_key)) + return cast("StateType", self._device.get_attribute(self._entity_key)) @property def device_class(self) -> SensorDeviceClass: """Return device class.""" - return cast(SensorDeviceClass, self._config.get("device_class")) + return cast("SensorDeviceClass", self._config.get("device_class")) @property def state_class(self) -> SensorStateClass | None: """Return state state.""" - return cast(SensorStateClass | None, self._config.get("state_class")) + return cast("SensorStateClass | None", self._config.get("state_class")) @property def native_unit_of_measurement(self) -> str | None: """Return unit of measurement.""" - return cast(str | None, self._config.get("unit")) + return cast("str | None", self._config.get("unit")) @property def capability_attributes(self) -> dict[str, Any] | None: diff --git a/custom_components/midea_ac_lan/switch.py b/custom_components/midea_ac_lan/switch.py index 196e599..ef4b6a8 100644 --- a/custom_components/midea_ac_lan/switch.py +++ b/custom_components/midea_ac_lan/switch.py @@ -24,7 +24,7 @@ async def async_setup_entry( extra_switches = config_entry.options.get(CONF_SWITCHES, []) switches = [] for entity_key, config in cast( - dict, + "dict", MIDEA_DEVICES[device.device_type]["entities"], ).items(): if config["type"] == Platform.SWITCH and entity_key in extra_switches: @@ -39,7 +39,7 @@ class MideaSwitch(MideaEntity, ToggleEntity): @property def is_on(self) -> bool: """Return true if switch is on.""" - return cast(bool, self._device.get_attribute(self._entity_key)) + return cast("bool", self._device.get_attribute(self._entity_key)) def turn_on(self, **kwargs: Any) -> None: # noqa: ANN401, ARG002 """Turn on switch.""" diff --git a/custom_components/midea_ac_lan/water_heater.py b/custom_components/midea_ac_lan/water_heater.py index 24270ad..793f5d5 100644 --- a/custom_components/midea_ac_lan/water_heater.py +++ b/custom_components/midea_ac_lan/water_heater.py @@ -62,7 +62,7 @@ async def async_setup_entry( | MideaCDWaterHeater ] = [] for entity_key, config in cast( - dict, + "dict", MIDEA_DEVICES[device.device_type]["entities"], ).items(): if config["type"] == Platform.WATER_HEATER and ( @@ -133,7 +133,7 @@ def temperature_unit(self) -> UnitOfTemperature: def current_operation(self) -> str | None: """Midea Water Heater current operation.""" return cast( - str, + "str", ( self._device.get_attribute("mode") if self._device.get_attribute("power") @@ -144,12 +144,12 @@ def current_operation(self) -> str | None: @property def current_temperature(self) -> float: """Midea Water Heater current temperature.""" - return cast(float, self._device.get_attribute("current_temperature")) + return cast("float", self._device.get_attribute("current_temperature")) @property def target_temperature(self) -> float: """Midea Water Heater target temperature.""" - return cast(float, self._device.get_attribute("target_temperature")) + return cast("float", self._device.get_attribute("target_temperature")) def set_temperature(self, **kwargs: Any) -> None: # noqa: ANN401 """Midea Water Heater set temperature.""" @@ -167,7 +167,7 @@ def operation_list(self) -> list[str] | None: """Midea Water Heater operation list.""" if not hasattr(self._device, "preset_modes"): return None - return cast(list, self._device.preset_modes) + return cast("list", self._device.preset_modes) def turn_on(self, **kwargs: Any) -> None: # noqa: ANN401, ARG002 """Midea Water Heater turn on.""" @@ -279,14 +279,14 @@ def current_operation(self) -> str: def current_temperature(self) -> float: """Midea C3 Water Heater current temperature.""" return cast( - float, + "float", self._device.get_attribute(C3Attributes.tank_actual_temperature), ) @property def target_temperature(self) -> float: """Midea C3 Water Heater target temperature.""" - return cast(float, self._device.get_attribute(C3Attributes.dhw_target_temp)) + return cast("float", self._device.get_attribute(C3Attributes.dhw_target_temp)) def set_temperature(self, **kwargs: Any) -> None: # noqa: ANN401 """Midea C3 Water Heater set temperature.""" @@ -298,12 +298,12 @@ def set_temperature(self, **kwargs: Any) -> None: # noqa: ANN401 @property def min_temp(self) -> float: """Midea C3 Water Heater min temperature.""" - return cast(float, self._device.get_attribute(C3Attributes.dhw_temp_min)) + return cast("float", self._device.get_attribute(C3Attributes.dhw_temp_min)) @property def max_temp(self) -> float: """Midea C3 Water Heater max temperature.""" - return cast(float, self._device.get_attribute(C3Attributes.dhw_temp_max)) + return cast("float", self._device.get_attribute(C3Attributes.dhw_temp_max)) def turn_on(self, **kwargs: Any) -> None: # noqa: ANN401, ARG002 """Midea C3 Water Heater turn on.""" @@ -364,12 +364,12 @@ def current_operation(self) -> str: @property def current_temperature(self) -> float: """Midea E6 Water Heater current temperature.""" - return cast(float, self._device.get_attribute(self._current_temperature_attr)) + return cast("float", self._device.get_attribute(self._current_temperature_attr)) @property def target_temperature(self) -> float: """Midea E6 Water Heater target temperature.""" - return cast(float, self._device.get_attribute(self._target_temperature_attr)) + return cast("float", self._device.get_attribute(self._target_temperature_attr)) def set_temperature(self, **kwargs: Any) -> None: # noqa: ANN401 """Midea E6 Water Heater set temperature.""" @@ -382,11 +382,11 @@ def set_temperature(self, **kwargs: Any) -> None: # noqa: ANN401 def min_temp(self) -> float: """Midea E6 Water Heater min temperature.""" min_temperature = cast( - list[str], + "list[str]", self._device.get_attribute(E6Attributes.min_temperature), ) return cast( - float, + "float", min_temperature[self._use], ) @@ -394,11 +394,11 @@ def min_temp(self) -> float: def max_temp(self) -> float: """Midea E6 Water Heater max temperature.""" max_temperature = cast( - list[str], + "list[str]", self._device.get_attribute(E6Attributes.max_temperature), ) return cast( - float, + "float", max_temperature[self._use], ) @@ -431,9 +431,9 @@ def supported_features(self) -> WaterHeaterEntityFeature: @property def min_temp(self) -> float: """Midea CD Water Heater min temperature.""" - return cast(float, self._device.get_attribute(CDAttributes.min_temperature)) + return cast("float", self._device.get_attribute(CDAttributes.min_temperature)) @property def max_temp(self) -> float: """Midea CD Water Heater max temperature.""" - return cast(float, self._device.get_attribute(CDAttributes.max_temperature)) + return cast("float", self._device.get_attribute(CDAttributes.max_temperature))