Add Midea washing and drying machines sensors (#184331)

Co-authored-by: Norbert Rittel <norbert@rittel.de>
This commit is contained in:
Lucas Mindêllo de Andrade
2026-10-09 16:13:02 +02:00
committed by GitHub
co-authored by Norbert Rittel
parent a3044b6055
commit 45affc4a40
5 changed files with 2042 additions and 7 deletions
+24
View File
@@ -44,6 +44,18 @@
}
},
"sensor": {
"dehydration_level": {
"default": "mdi:tumble-dryer"
},
"dehydration_speed": {
"default": "mdi:speedometer"
},
"detergent": {
"default": "mdi:bottle-tonic"
},
"dry_program": {
"default": "mdi:tumble-dryer"
},
"filter_life": {
"default": "mdi:air-filter"
},
@@ -76,6 +88,18 @@
},
"time_remaining": {
"default": "mdi:progress-clock"
},
"wash_program": {
"default": "mdi:washing-machine"
},
"wash_progress": {
"default": "mdi:rotate-360"
},
"wash_strength": {
"default": "mdi:network-strength-4-cog"
},
"water_level": {
"default": "mdi:cup-water"
}
},
"switch": {
+333 -3
View File
@@ -43,6 +43,7 @@ PARALLEL_UPDATES = 0
class MideaSensorEntityDescription(SensorEntityDescription):
"""Describes Midea sensor entity."""
attribute: str | None = None
models: list[DeviceType] | None = None
@@ -704,6 +705,313 @@ SENSOR_ENTITIES: list[MideaSensorEntityDescription] = [
native_unit_of_measurement=UnitOfVolume.LITERS,
state_class=SensorStateClass.MEASUREMENT,
),
MideaSensorEntityDescription(
key="progress",
translation_key="wash_progress",
device_class=SensorDeviceClass.ENUM,
options=[
"idle",
"spin",
"rinse",
"wash",
"weight",
"dry",
"soak",
],
models=[DeviceType.DA],
),
MideaSensorEntityDescription(
key="program",
translation_key="wash_program",
device_class=SensorDeviceClass.ENUM,
options=[
"standard",
"fast",
"blanket",
"wool",
"embathe",
"memory",
"child",
"down_jacket",
"stir",
"mute",
"bucket_self_clean",
"air_dry",
],
models=[DeviceType.DA],
),
MideaSensorEntityDescription(
key="dehydration_level",
attribute="dehydration_speed",
translation_key="dehydration_level",
device_class=SensorDeviceClass.ENUM,
options=["none", "low", "medium", "high"],
models=[DeviceType.DA],
),
MideaSensorEntityDescription(
key="detergent",
translation_key="detergent",
device_class=SensorDeviceClass.ENUM,
options=[
"no",
"less",
"medium",
"more",
"4",
"5",
"6",
"7",
"8",
"insufficient",
],
models=[DeviceType.DA],
),
MideaSensorEntityDescription(
key="softener",
translation_key="softener",
device_class=SensorDeviceClass.ENUM,
options=[
"no",
"intelligent",
"programed", # codespell:ignore
"3",
"4",
"5",
"6",
"7",
"8",
"insufficient",
],
models=[DeviceType.DA],
),
MideaSensorEntityDescription(
key="wash_strength",
translation_key="wash_strength",
device_class=SensorDeviceClass.ENUM,
options=["none", "weak", "medium", "strong"],
models=[DeviceType.DA],
),
MideaSensorEntityDescription(
key="status",
translation_key="status",
device_class=SensorDeviceClass.ENUM,
options=[
"idle",
"standby",
"start",
"pause",
"end",
"fault",
"delay",
],
models=[DeviceType.DB],
),
MideaSensorEntityDescription(
key="dehydration_speed",
translation_key="dehydration_speed",
native_unit_of_measurement=REVOLUTIONS_PER_MINUTE,
state_class=SensorStateClass.MEASUREMENT,
models=[DeviceType.DB],
),
MideaSensorEntityDescription(
key="water_level",
translation_key="water_level",
device_class=SensorDeviceClass.ENUM,
options=[
"low",
"mid",
"high",
"4",
"auto",
],
models=[DeviceType.DB],
),
MideaSensorEntityDescription(
key="program",
translation_key="wash_program",
device_class=SensorDeviceClass.ENUM,
options=[
"cotton",
"eco",
"fast_wash",
"mixed_wash",
"fiber",
"wool",
"enzyme",
"ssp",
"sport_clothes",
"single_dehytration",
"rinsing_dehydration",
"big",
"baby_clothes",
"outdoor",
"air_wash",
"down_jacket",
"color",
"intelligent",
"quick_wash",
"kids",
"water_cotton",
"single_drying",
"fast_wash_30",
"fast_wash_60",
"water_intelligent",
"water_steep",
"water_fast_wash_30",
"shirt",
"steep",
"new_water_cotton",
"water_mixed_wash",
"water_fiber",
"water_kids",
"water_underwear",
"specialist",
"water_eco",
"wash_drying_60",
"self_wash_5",
"fast_wash_min",
"mixed_wash_min",
"dehydration_min",
"self_wash_min",
"baby_clothes_min",
"prevent_allergy",
"cold_wash",
"soft_wash",
"remove_mite_wash",
"water_intense_wash",
"fast_dry",
"water_outdoor",
"spring_autumn_wash",
"summer_wash",
"winter_wash",
"jean",
"new_clothes_wash",
"silk",
"insight_wash",
"fitness_clothes",
"mink",
"fresh_air",
"bucket_dry",
"jacket",
"bath_towel",
"night_fresh_wash",
"diy0",
"diy2",
"heart_wash",
"water_cold_wash",
"water_prevent_allergy",
"water_remove_mite_wash",
"water_ssp",
"silk_wash",
"standard",
"green_wool",
"cook_wash",
"fresh_remove_wrinkle",
"steam_sterilize_wash",
"aromatherapy",
"eco_40_60",
"steam_care",
"allergy_care",
"sterilize_wash",
"wash_and_dry",
"time_dry",
"bulky",
"love",
],
models=[DeviceType.DB],
),
MideaSensorEntityDescription(
key="progress",
translation_key="wash_progress",
device_class=SensorDeviceClass.ENUM,
options=[
"idle",
"spin",
"rinse",
"wash",
"pre_wash",
"dry",
"weight",
"hi_speed_spin",
],
models=[DeviceType.DB],
),
MideaSensorEntityDescription(
key="status",
translation_key="status",
device_class=SensorDeviceClass.ENUM,
options=[
"idle",
"standby",
"start",
"pause",
"end",
"prevent_wrinkle_end",
"delay_choosing",
"fault",
"delay",
"delay_pause",
],
models=[DeviceType.DC],
),
MideaSensorEntityDescription(
key="program",
translation_key="dry_program",
device_class=SensorDeviceClass.ENUM,
options=[
"cotton",
"fiber",
"mixed_wash",
"jean",
"bedsheet",
"outdoor",
"down_jacket",
"plush",
"wool",
"dehumidify",
"cold_air_fresh_air",
"hot_air_dry",
"sport_clothes",
"underwear",
"baby_clothes",
"shirt",
"standard",
"quick_dry",
"fresh_air",
"low_temp_dry",
"eco_dry",
"quick_dry_30",
"towel",
"intelligent_dry",
"steam_care",
"big",
"fixed_time_dry",
"night_dry",
"bracket_dry",
"western_trouser",
"dehumidification",
"smart_dry",
"four_piece_suit",
"warm_clothes",
"quick_dry_20",
"steam_sterilize",
"enzyme",
"big_60",
"steam_no_iron",
"air_wash",
"bed_clothes",
"little_fast_dry",
"small_piece_dry",
"big_dry",
"wool_nurse",
"sun_quilt",
"fresh_remove_smell",
"bucket_self_clean",
"silk",
"sterilize",
],
models=[DeviceType.DC],
),
]
@@ -718,7 +1026,7 @@ async def async_setup_entry(
sensors: list[MideaSensor] = [
MideaSensor(device, description)
for description in SENSOR_ENTITIES
if device.attributes.get(description.key) is not None
if device.attributes.get(description.attribute or description.key) is not None
and (not description.models or device.device_type in description.models)
]
@@ -732,10 +1040,32 @@ class MideaSensor(MideaEntity, SensorEntity):
@override
def native_value(self) -> StateType | datetime:
"""Native value of the sensor."""
value = self._device.get_attribute(self.entity_description.key)
description = cast(MideaSensorEntityDescription, self.entity_description)
value = self._device.get_attribute(description.attribute or description.key)
if value == "unknown":
return None
if self.entity_description.device_class == SensorDeviceClass.TIMESTAMP:
if (
description.key
in (
"dehydration_level",
"softener",
"detergent",
"temperature",
"water_level",
"program",
)
and value == "default"
):
return None
if isinstance(value, str) and (
description.translation_key == "dehydration_speed"
or description.key == "temperature"
):
try:
return cast("StateType", float(value))
except ValueError:
return None
if description.device_class == SensorDeviceClass.TIMESTAMP:
if not isinstance(value, (int, float)) or value <= 0:
return None
# round to the closest minute
+237
View File
@@ -385,12 +385,94 @@
"current_energy_consumption": {
"name": "Current energy consumption"
},
"dehydration_level": {
"name": "Dehydration level",
"state": {
"high": "[%key:common::state::high%]",
"low": "[%key:common::state::low%]",
"medium": "[%key:common::state::medium%]",
"none": "None"
}
},
"dehydration_speed": {
"name": "Dehydration speed"
},
"dehydration_time": {
"name": "Dehydration time"
},
"detergent": {
"name": "Detergent",
"state": {
"4": "4",
"5": "5",
"6": "6",
"7": "7",
"8": "8",
"insufficient": "Insufficient",
"less": "Less",
"medium": "[%key:common::state::medium%]",
"more": "More",
"no": "None"
}
},
"discharge_pipe_temperature": {
"name": "Discharge pipe temperature"
},
"dry_program": {
"name": "Dry program",
"state": {
"air_wash": "Air wash",
"baby_clothes": "Baby clothes",
"bed_clothes": "Bed clothes",
"bedsheet": "Bedsheet",
"big": "Big",
"big_60": "Big 60",
"big_dry": "Big dry",
"bracket_dry": "Bracket dry",
"bucket_self_clean": "Bucket self clean",
"cold_air_fresh_air": "Cold air fresh air",
"cotton": "Cotton",
"dehumidification": "Dehumidification",
"dehumidify": "Dehumidify",
"down_jacket": "Down jacket",
"eco_dry": "Eco dry",
"enzyme": "Enzyme",
"fiber": "Fiber",
"fixed_time_dry": "Fixed time dry",
"four_piece_suit": "Four piece suit",
"fresh_air": "Fresh air",
"fresh_remove_smell": "Fresh remove smell",
"hot_air_dry": "Hot air dry",
"intelligent_dry": "Intelligent dry",
"jean": "Jeans",
"little_fast_dry": "Little fast dry",
"low_temp_dry": "Low temperature dry",
"mixed_wash": "Mixed wash",
"night_dry": "Night dry",
"outdoor": "Outdoor",
"plush": "Plush",
"quick_dry": "Quick dry",
"quick_dry_20": "Quick dry 20",
"quick_dry_30": "Quick dry 30",
"shirt": "Shirt",
"silk": "Silk",
"small_piece_dry": "Small piece dry",
"smart_dry": "Smart dry",
"sport_clothes": "Sport clothes",
"standard": "Standard",
"steam_care": "Steam care",
"steam_no_iron": "Steam no iron",
"steam_sterilize": "Steam sterilize",
"sterilize": "Sterilize",
"sun_quilt": "Sun quilt",
"towel": "Towel",
"underwear": "Underwear",
"warm_clothes": "Warm clothes",
"western_trouser": "Western trouser",
"wool": "Wool",
"wool_nurse": "Wool nurse"
}
},
"dry_temperature": {
"name": "Dry temperature"
},
@@ -602,6 +684,21 @@
"soak_time": {
"name": "Soak time"
},
"softener": {
"name": "Softener",
"state": {
"3": "3",
"4": "4",
"5": "5",
"6": "6",
"7": "7",
"8": "8",
"insufficient": "Insufficient",
"intelligent": "Intelligent",
"no": "None",
"programed": "Programmed"
}
},
"softwater_available": {
"name": "Soft water available"
},
@@ -609,10 +706,17 @@
"name": "Status",
"state": {
"delay": "Delayed",
"delay_choosing": "Delay choosing",
"delay_pause": "Delay paused",
"end": "End",
"fault": "[%key:common::state::fault%]",
"finished": "Finished",
"idle": "[%key:common::state::idle%]",
"pause": "[%key:common::state::paused%]",
"paused": "[%key:common::state::paused%]",
"prevent_wrinkle_end": "Prevent wrinkle end",
"standby": "[%key:common::state::standby%]",
"start": "Start",
"working": "Working"
}
},
@@ -677,6 +781,129 @@
"zero_fresh": "Zero fresh"
}
},
"wash_program": {
"name": "Wash program",
"state": {
"air_dry": "Air dry",
"air_wash": "Air wash",
"allergy_care": "Allergy care",
"aromatherapy": "Aromatherapy",
"baby_clothes": "Baby clothes",
"baby_clothes_min": "Baby clothes min",
"bath_towel": "Bath towel",
"big": "Big",
"blanket": "Blanket",
"bucket_dry": "Bucket dry",
"bucket_self_clean": "Bucket self clean",
"bulky": "Bulky",
"child": "Child",
"cold_wash": "Cold wash",
"color": "Color",
"cook_wash": "Cook wash",
"cotton": "Cotton",
"dehydration_min": "Dehydration min",
"diy0": "DIY 0",
"diy2": "DIY 2",
"down_jacket": "Down jacket",
"eco": "Eco",
"eco_40_60": "Eco 40-60",
"embathe": "Embathe",
"enzyme": "Enzyme",
"fast": "Fast",
"fast_dry": "Fast dry",
"fast_wash": "Fast wash",
"fast_wash_30": "Fast wash 30",
"fast_wash_60": "Fast wash 60",
"fast_wash_min": "Fast wash min",
"fiber": "Fiber",
"fitness_clothes": "Fitness clothes",
"fresh_air": "Fresh air",
"fresh_remove_wrinkle": "Fresh remove wrinkle",
"green_wool": "Green wool",
"heart_wash": "Heart wash",
"insight_wash": "Insight wash",
"intelligent": "Intelligent",
"jacket": "Jacket",
"jean": "Jean",
"kids": "Kids",
"love": "Love",
"memory": "Memory",
"mink": "Mink",
"mixed_wash": "Mixed wash",
"mixed_wash_min": "Mixed wash min",
"mute": "Mute",
"new_clothes_wash": "New clothes wash",
"new_water_cotton": "New water cotton",
"night_fresh_wash": "Night fresh wash",
"outdoor": "Outdoor",
"prevent_allergy": "Prevent allergy",
"quick_wash": "Quick wash",
"remove_mite_wash": "Remove mite wash",
"rinsing_dehydration": "Rinsing dehydration",
"self_wash_5": "Self wash 5",
"self_wash_min": "Self wash min",
"shirt": "Shirt",
"silk": "Silk",
"silk_wash": "Silk wash",
"single_dehytration": "Single dehydration",
"single_drying": "Single drying",
"soft_wash": "Soft wash",
"specialist": "Specialist",
"sport_clothes": "Sport clothes",
"spring_autumn_wash": "Spring autumn wash",
"ssp": "SSP",
"standard": "Standard",
"steam_care": "Steam care",
"steam_sterilize_wash": "Steam sterilize wash",
"steep": "Steep",
"sterilize_wash": "Sterilize wash",
"stir": "Stir",
"summer_wash": "Summer wash",
"time_dry": "Time dry",
"wash_and_dry": "Wash and dry",
"wash_drying_60": "Wash and dry 60",
"water_cold_wash": "Water cold wash",
"water_cotton": "Water cotton",
"water_eco": "Water eco",
"water_fast_wash_30": "Water fast wash 30",
"water_fiber": "Water fiber",
"water_intelligent": "Water intelligent",
"water_intense_wash": "Water intense wash",
"water_kids": "Water kids",
"water_mixed_wash": "Water mixed wash",
"water_outdoor": "Water outdoor",
"water_prevent_allergy": "Water prevent allergy",
"water_remove_mite_wash": "Water remove mite wash",
"water_ssp": "Water SSP",
"water_steep": "Water steep",
"water_underwear": "Water underwear",
"winter_wash": "Winter wash",
"wool": "Wool"
}
},
"wash_progress": {
"name": "Wash progress",
"state": {
"dry": "Drying",
"hi_speed_spin": "High Speed Spinning",
"idle": "[%key:common::state::idle%]",
"pre_wash": "Pre-washing",
"rinse": "Rinsing",
"soak": "Soaking",
"spin": "Spinning",
"wash": "Washing",
"weight": "Weighing"
}
},
"wash_strength": {
"name": "Wash strength",
"state": {
"medium": "[%key:common::state::medium%]",
"none": "None",
"strong": "Strong",
"weak": "Weak"
}
},
"wash_time": {
"name": "Wash time"
},
@@ -689,6 +916,16 @@
"water_consumption_big": {
"name": "Water consumption aggregated"
},
"water_level": {
"name": "Water level",
"state": {
"4": "4",
"auto": "[%key:common::state::auto%]",
"high": "[%key:common::state::high%]",
"low": "[%key:common::state::low%]",
"mid": "[%key:common::state::medium%]"
}
},
"water_temperature": {
"name": "Water temperature"
}
File diff suppressed because it is too large Load Diff
+66 -2
View File
@@ -9,7 +9,9 @@ from midealocal.devices.ac import DeviceAttributes as ACAttributes
from midealocal.devices.b1 import DeviceAttributes as B1Attributes
from midealocal.devices.c3 import DeviceAttributes as C3Attributes
from midealocal.devices.ca import MideaCADevice
from midealocal.devices.da import DeviceAttributes as DAAttributes
from midealocal.devices.db import DeviceAttributes as DBAttributes, MideaDBDevice
from midealocal.devices.dc import DeviceAttributes as DCAttributes
from midealocal.devices.e8 import DeviceAttributes as E8Attributes
from midealocal.devices.ea import DeviceAttributes as EAAttributes, MideaEADevice
from midealocal.devices.ec import DeviceAttributes as ECAttributes, MideaECDevice
@@ -97,27 +99,56 @@ from tests.common import MockConfigEntry, snapshot_platform
),
id="e8",
),
pytest.param(
DummyDevice(
DeviceType.DA,
attributes={
DAAttributes.progress: "weight",
DAAttributes.program: "wool",
DAAttributes.dehydration_speed: "low",
DAAttributes.detergent: "no",
DAAttributes.softener: "default",
DAAttributes.wash_strength: "weak",
},
),
id="da",
),
pytest.param(
DummyDevice(
DeviceType.DB,
attributes={
DBAttributes.power: True,
DBAttributes.mode: "normal",
DBAttributes.temperature: 22.0,
DBAttributes.temperature: "60",
DBAttributes.wash_time: 65,
DBAttributes.dehydration_time: 30,
DBAttributes.program: "cotton",
DBAttributes.status: "pause",
DBAttributes.dehydration_speed: "1400",
DBAttributes.water_level: "low",
DBAttributes.progress: "rinse",
},
),
id="db",
),
pytest.param(
DummyDevice(
DeviceType.DC,
attributes={
DCAttributes.power: True,
DCAttributes.status: "prevent_wrinkle_end",
DCAttributes.program: "bedsheet",
},
),
id="dc",
),
pytest.param(
DummyDevice(
DeviceType.DB,
attributes={
DBAttributes.power: False,
DBAttributes.mode: "unknown",
DBAttributes.temperature: 22.0,
DBAttributes.temperature: "70",
DBAttributes.wash_time: 65,
DBAttributes.dehydration_time: 30,
DBAttributes.program: "unknown",
@@ -265,6 +296,39 @@ async def test_sensor_state_update(
assert state.state == "unknown"
async def test_db_sensor_with_invalid_dehydration_speed(
hass: HomeAssistant,
set_device_attribute: SetDeviceAttribute,
mock_config_entry: Callable[[DummyDevice], MockConfigEntry],
) -> None:
"""Test DB sensor with invalid dehydration_speed."""
device = DummyDevice(
DeviceType.DB,
attributes={
DBAttributes.power: True,
DBAttributes.mode: "normal",
DBAttributes.temperature: "40",
DBAttributes.wash_time: 65,
DBAttributes.dehydration_time: 30,
DBAttributes.program: "cotton",
DBAttributes.status: "pause",
DBAttributes.dehydration_speed: "-",
DBAttributes.water_level: "low",
DBAttributes.progress: "rinse",
},
)
config_entry = mock_config_entry(device)
with patch("homeassistant.components.midea._PLATFORMS", [Platform.SENSOR]):
await setup_integration(hass, config_entry, device)
entity_entry = entity_entries(hass, config_entry)[
f"{TEST_DEVICE_ID}_dehydration_speed"
]
state = hass.states.get(entity_entry.entity_id)
assert state is not None
assert state.state == "unknown"
async def test_time_remaining_sensor_as_timestamp(
hass: HomeAssistant,
freezer: FrozenDateTimeFactory,