Skip to content

Commit

Permalink
chore(pre-commit.ci): auto fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Dec 3, 2024
1 parent 1b38497 commit a6b200c
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 94 deletions.
6 changes: 3 additions & 3 deletions custom_components/midea_ac_lan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 (
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions custom_components/midea_ac_lan/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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))
56 changes: 31 additions & 25 deletions custom_components/midea_ac_lan/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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:
Expand All @@ -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."""
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -321,7 +321,9 @@ def swing_mode(self) -> str:
@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."""
Expand Down Expand Up @@ -362,18 +364,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),
)

Expand Down Expand Up @@ -424,27 +426,29 @@ 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):
Expand Down Expand Up @@ -482,7 +486,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:
Expand All @@ -496,7 +500,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(
Expand All @@ -507,31 +511,31 @@ 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],
)

@property
def max_temp(self) -> float:
"""Midea C3 Climate max temperature."""
return cast(
float,
"float",
self._temperature(False)[self._zone],
)

@property
def target_temperature_low(self) -> float:
"""Midea C3 Climate target temperature low."""
return cast(
float,
"float",
self._temperature(True)[self._zone],
)

@property
def target_temperature_high(self) -> float:
"""Midea C3 Climate target temperature high."""
return cast(
float,
"float",
self._temperature(False)[self._zone],
)

Expand All @@ -555,11 +559,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],
)

Expand Down Expand Up @@ -625,7 +629,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:
Expand All @@ -639,7 +643,9 @@ 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."""
Expand Down
4 changes: 2 additions & 2 deletions custom_components/midea_ac_lan/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions custom_components/midea_ac_lan/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions custom_components/midea_ac_lan/humidifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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."""
Expand All @@ -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."""
Expand Down
Loading

0 comments on commit a6b200c

Please sign in to comment.