Cleanup climate and sensor in Midea (#182483)

This commit is contained in:
Simone Chemelli
2026-09-17 18:23:58 +02:00
committed by GitHub
parent 9952d71a86
commit 8619748b34
4 changed files with 13 additions and 120 deletions
+1 -3
View File
@@ -409,9 +409,7 @@ class MideaACClimate(MideaClimate):
def current_humidity(self) -> float | None:
"""Return the current indoor humidity, or None if unavailable."""
raw = self._device.get_attribute(ACAttributes.indoor_humidity)
# Some devices report invalid values (0 or 0xFF) for this sensor
# so filter those out and return None instead.
if isinstance(raw, (int, float)) and raw not in {0, 0xFF}:
if isinstance(raw, (int, float)):
return float(raw)
return None
+4 -108
View File
@@ -4,6 +4,8 @@ from dataclasses import dataclass
from typing import cast, override
from midealocal.const import DeviceType
from midealocal.devices.ea import MideaEADevice
from midealocal.devices.ec import MideaECDevice
from homeassistant.components.sensor import (
EntityCategory,
@@ -42,106 +44,6 @@ class MideaSensorEntityDescription(SensorEntityDescription):
models: list[DeviceType] | None = None
COOKER_MODES: list[str] = [
"smart",
"reserve",
"cook_rice",
"fast_cook_rice",
"standard_cook_rice",
"gruel",
"cook_congee",
"stew_soup",
"stewing",
"heat_rice",
"make_cake",
"yoghourt",
"soup_rice",
"coarse_rice",
"five_ceeals_rice",
"eight_treasures_rice",
"crispy_rice",
"shelled_rice",
"eight_treasures_congee",
"infant_congee",
"older_rice",
"rice_soup",
"rice_paste",
"egg_custard",
"warm_milk",
"hot_spring_egg",
"millet_congee",
"firewood_rice",
"few_rice",
"red_potato",
"corn",
"quick_freeze_bun",
"steam_ribs",
"steam_egg",
"coarse_congee",
"steep_rice",
"appetizing_congee",
"corn_congee",
"sprout_rice",
"luscious_rice",
"luscious_boiled",
"fast_rice",
"fast_boil",
"bean_rice_congee",
"fast_congee",
"baby_congee",
"cook_soup",
"congee_coup",
"steam_corn",
"steam_red_potato",
"boil_congee",
"delicious_steam",
"boil_egg",
"rice_wine",
"fruit_vegetable_paste",
"vegetable_porridge",
"pork_porridge",
"fragrant_rice",
"assorte_rice",
"steame_fish",
"baby_rice",
"essence_rice",
"fragrant_dense_congee",
"one_two_cook",
"original_steame",
"hot_fast_rice",
"online_celebrity_rice",
"sushi_rice",
"stone_bowl_rice",
"no_water_treat",
"keep_fresh",
"low_sugar_rice",
"black_buckwheat_rice",
"resveratrol_rice",
"yellow_wheat_rice",
"green_buckwheat_rice",
"roughage_rice",
"millet_mixed_rice",
"iron_pan_rice",
"olla_pan_rice",
"vegetable_rice",
"baby_side",
"regimen_congee",
"earthen_pot_congee",
"regimen_soup",
"pottery_jar_soup",
"canton_soup",
"nutrition_stew",
"northeast_stew",
"uncap_boil",
"trichromatic_coarse_grain",
"four_color_vegetables",
"egg",
"chop",
"clean",
"keep_warm",
]
SENSOR_ENTITIES: list[MideaSensorEntityDescription] = [
MideaSensorEntityDescription(
key="indoor_humidity",
@@ -375,14 +277,14 @@ SENSOR_ENTITIES: list[MideaSensorEntityDescription] = [
translation_key="mode",
models=[DeviceType.EA],
device_class=SensorDeviceClass.ENUM,
options=COOKER_MODES,
options=MideaEADevice.mode_options(),
),
MideaSensorEntityDescription(
key="mode",
translation_key="mode",
models=[DeviceType.EC],
device_class=SensorDeviceClass.ENUM,
options=[*COOKER_MODES, "diy"],
options=MideaECDevice.mode_options(),
),
MideaSensorEntityDescription(
key="tank",
@@ -811,12 +713,6 @@ class MideaSensor(MideaEntity, SensorEntity):
def native_value(self) -> StateType:
"""Native value of the sensor."""
value = self._device.get_attribute(self.entity_description.key)
if (
self.entity_description.key == "indoor_humidity"
and isinstance(value, (int, float))
and value in {0, 0xFF}
):
return None
if value == "unknown":
return None
return cast("StateType", value)
+5 -6
View File
@@ -615,18 +615,17 @@ async def test_ac_set_temperature_without_hvac_mode(
@pytest.mark.parametrize(
("humidity", "expected_humidity"),
[
pytest.param(50, 50.0, id="normal"),
pytest.param(0, None, id="invalid_zero"),
pytest.param(0xFF, None, id="invalid_ff"),
pytest.param(50, 50.0, id="numeric"),
pytest.param(None, None, id="unavailable"),
],
)
async def test_ac_humidity_filtering(
async def test_ac_current_humidity(
hass: HomeAssistant,
mock_config_entry: Callable[[DummyDevice], MockConfigEntry],
humidity: int,
humidity: int | None,
expected_humidity: float | None,
) -> None:
"""Test AC humidity filtering for invalid sensor values."""
"""Test AC current_humidity reflects the device's raw attribute value."""
device = DummyDevice(
DeviceType.AC,
attributes={
+3 -3
View File
@@ -205,7 +205,7 @@ async def test_sensor_state_update(
ACAttributes.mode: 1,
ACAttributes.target_temperature: 22.0,
ACAttributes.indoor_temperature: 21.0,
ACAttributes.indoor_humidity: 0,
ACAttributes.indoor_humidity: 45,
ACAttributes.full_dust: False,
ACAttributes.outdoor_temperature: "unknown",
},
@@ -241,9 +241,9 @@ async def test_sensor_state_update(
]
state = hass.states.get(entity_entry.entity_id)
assert state is not None
assert state.state == "unknown"
assert state.state == "45"
await set_device_attribute(device, ACAttributes.indoor_humidity, 255)
await set_device_attribute(device, ACAttributes.indoor_humidity, None)
state = hass.states.get(entity_entry.entity_id)
assert state is not None
assert state.state == "unknown"