From 50108e3ea7913d8a0ade9be57ceda6f48e05de85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85ke=20S=20-=20Piper?= Date: Wed, 22 Nov 2023 10:53:01 +0000 Subject: [PATCH 1/2] Improve detection of heating zones --- custom_components/miele/devcap.py | 2 +- custom_components/miele/number.py | 69 ++++++++++++++++++++----------- 2 files changed, 47 insertions(+), 24 deletions(-) diff --git a/custom_components/miele/devcap.py b/custom_components/miele/devcap.py index 2a732633..d2a6cfee 100644 --- a/custom_components/miele/devcap.py +++ b/custom_components/miele/devcap.py @@ -968,7 +968,7 @@ "deviceIdentLabel": { "fabNumber": "**REDACTED**", "fabIndex": "00", - "techType": "KM7897", + "techType": "KM7897 R02", "matNumber": "", "swids": ["000"], }, diff --git a/custom_components/miele/number.py b/custom_components/miele/number.py index 128a4ef0..55197ec3 100644 --- a/custom_components/miele/number.py +++ b/custom_components/miele/number.py @@ -12,7 +12,8 @@ NumberMode, ) from homeassistant.core import HomeAssistant -from homeassistant.helpers import issue_registry as ir + +# from homeassistant.helpers import issue_registry as ir from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType @@ -62,15 +63,27 @@ 217: 110, } -DEFAULT_PLATE_COUNT = 6 +DEFAULT_PLATE_COUNT = 4 PLATE_COUNT = { - "KM7474": 4, + "KM7678": 6, + "KM7697": 6, + "KM7878": 6, "KM7897": 6, + "KMDA7633": 5, "KMDA7634": 5, } +def get_plate_count(tech_type): + """Get number of zones.""" + stripped = tech_type.replace(" ", "") + for prefix, plates in PLATE_COUNT.items(): + if stripped.startswith(prefix): + return plates + return DEFAULT_PLATE_COUNT + + @dataclass class MieleNumberDescriptionMixin: """Required values when describing Miele number entities.""" @@ -106,29 +119,39 @@ async def async_setup_entry( entities = [] for idx, ent in enumerate(coordinator.data): - if ( - coordinator.data[ent]["ident|type|value_raw"] in HOB_TYPES - and coordinator.data[ent]["ident|deviceIdentLabel|techType"] - not in PLATE_COUNT - ): - ir.async_create_issue( - hass, - DOMAIN, - "hob_not_supported", - is_fixable=False, - severity=ir.IssueSeverity.WARNING, - translation_key="hob_not_supported", - translation_placeholders={ - "tech_type": coordinator.data[ent][ - "ident|deviceIdentLabel|techType" - ], - "issue_url": "https://github.com/astrandb/miele/issues", - }, - ) + # if ( + # coordinator.data[ent]["ident|type|value_raw"] in HOB_TYPES + # and coordinator.data[ent]["ident|deviceIdentLabel|techType"] + # not in PLATE_COUNT + # ): + # ir.async_create_issue( + # hass, + # DOMAIN, + # "hob_not_supported", + # is_fixable=False, + # severity=ir.IssueSeverity.WARNING, + # translation_key="hob_not_supported", + # translation_placeholders={ + # "tech_type": coordinator.data[ent][ + # "ident|deviceIdentLabel|techType" + # ], + # "issue_url": "https://github.com/astrandb/miele/issues", + # }, + # ) if coordinator.data[ent]["ident|type|value_raw"] in HOB_TYPES: tech_type = coordinator.data[ent]["ident|deviceIdentLabel|techType"] - plates = PLATE_COUNT.get(tech_type, DEFAULT_PLATE_COUNT) + plates = get_plate_count(tech_type) + api_plates = 0 + for i in range(8): + if f"state|plateStep|{i}|value_raw" in coordinator.data[ent]: + api_plates = i + if plates < api_plates + 1: + _LOGGER.warning( + "Inconsistent number of zones - API %s reports %s zones", + tech_type, + api_plates + 1, + ) for plate_no in range(plates): description = MieleNumberDescription( key="plate", From b7028e66649b55706dfebbc93605fd12e801a832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=85ke=20S=20-=20Piper?= Date: Wed, 22 Nov 2023 11:09:36 +0000 Subject: [PATCH 2/2] Improve logic to detect no of zones --- custom_components/miele/number.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/custom_components/miele/number.py b/custom_components/miele/number.py index 55197ec3..caf17539 100644 --- a/custom_components/miele/number.py +++ b/custom_components/miele/number.py @@ -141,11 +141,15 @@ async def async_setup_entry( if coordinator.data[ent]["ident|type|value_raw"] in HOB_TYPES: tech_type = coordinator.data[ent]["ident|deviceIdentLabel|techType"] - plates = get_plate_count(tech_type) api_plates = 0 for i in range(8): if f"state|plateStep|{i}|value_raw" in coordinator.data[ent]: api_plates = i + if api_plates == 0: + plates = get_plate_count(tech_type) + else: + plates = api_plates + 1 + if plates < api_plates + 1: _LOGGER.warning( "Inconsistent number of zones - API %s reports %s zones",