feat: convert the mode of the ptc bath heater to the preset mode (#874)

This commit is contained in:
Li Shuzhen 2025-03-13 17:37:44 +08:00 committed by GitHub
parent 8be0fa5d61
commit 8f0a69c611
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 41 deletions

View File

@ -605,7 +605,7 @@ class AirConditioner(FeatureOnOff, FeatureTargetTemperature,
class PtcBathHeater(FeatureTargetTemperature, FeatureTemperature, class PtcBathHeater(FeatureTargetTemperature, FeatureTemperature,
FeatureFanMode, FeatureSwingMode): FeatureFanMode, FeatureSwingMode, FeaturePresetMode):
"""Ptc bath heater""" """Ptc bath heater"""
_prop_mode: Optional[MIoTSpecProperty] _prop_mode: Optional[MIoTSpecProperty]
_hvac_mode_map: Optional[dict[int, HVACMode]] _hvac_mode_map: Optional[dict[int, HVACMode]]
@ -626,26 +626,20 @@ class PtcBathHeater(FeatureTargetTemperature, FeatureTemperature,
continue continue
self._hvac_mode_map = {} self._hvac_mode_map = {}
for item in prop.value_list.items: for item in prop.value_list.items:
if item.name in {'off', 'idle' if item.name in {'off', 'idle'}:
} and (HVACMode.OFF not in list( if (HVACMode.OFF
self._hvac_mode_map.values())): not in list(self._hvac_mode_map.values())):
self._hvac_mode_map[item.value] = HVACMode.OFF self._hvac_mode_map[item.value] = HVACMode.OFF
elif item.name in {'auto'}: elif (HVACMode.AUTO
not in list(self._hvac_mode_map.values())):
self._hvac_mode_map[item.value] = HVACMode.AUTO self._hvac_mode_map[item.value] = HVACMode.AUTO
elif item.name in {'ventilate'}:
self._hvac_mode_map[item.value] = HVACMode.COOL
elif item.name in {'heat', 'quick_heat'
} and (HVACMode.HEAT not in list(
self._hvac_mode_map.values())):
self._hvac_mode_map[item.value] = HVACMode.HEAT
elif item.name in {'defog'}:
self._hvac_mode_map[item.value] = HVACMode.HEAT_COOL
elif item.name in {'dry'}:
self._hvac_mode_map[item.value] = HVACMode.DRY
elif item.name in {'fan'}:
self._hvac_mode_map[item.value] = HVACMode.FAN_ONLY
self._attr_hvac_modes = list(self._hvac_mode_map.values()) self._attr_hvac_modes = list(self._hvac_mode_map.values())
self._prop_mode = prop if HVACMode.OFF in self._attr_hvac_modes:
self._prop_mode = prop
else:
_LOGGER.error('no idle mode, %s', self.entity_id)
# preset modes
self._init_preset_modes('ptc-bath-heater', 'mode')
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None: async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
"""Set the target hvac mode.""" """Set the target hvac mode."""
@ -655,15 +649,20 @@ class PtcBathHeater(FeatureTargetTemperature, FeatureTemperature,
if mode_value is None or not await self.set_property_async( if mode_value is None or not await self.set_property_async(
prop=self._prop_mode, value=mode_value): prop=self._prop_mode, value=mode_value):
raise RuntimeError( raise RuntimeError(
f'set climate prop.mode failed, {hvac_mode}, {self.entity_id}') f'set ptc-bath-heater {hvac_mode} failed, {self.entity_id}')
@property @property
def hvac_mode(self) -> Optional[HVACMode]: def hvac_mode(self) -> Optional[HVACMode]:
"""The current hvac mode.""" """The current hvac mode."""
return (self.get_map_value(map_=self._hvac_mode_map, if self._prop_mode is None:
key=self.get_prop_value( return None
prop=self._prop_mode)) mode_value = self.get_map_value(
if self._prop_mode else None) map_=self._hvac_mode_map,
key=self.get_prop_value(prop=self._prop_mode))
if mode_value == HVACMode.OFF or mode_value is None:
return mode_value
return HVACMode.AUTO if (HVACMode.AUTO
in self._attr_hvac_modes) else None
class Thermostat(FeatureOnOff, FeatureTargetTemperature, FeatureTemperature, class Thermostat(FeatureOnOff, FeatureTargetTemperature, FeatureTemperature,

View File

@ -138,7 +138,7 @@ SPEC_DEVICE_TRANS_MAP: dict = {
'optional': { 'optional': {
'properties': {'mode', 'target-humidity'} 'properties': {'mode', 'target-humidity'}
} }
}, }
}, },
'optional': { 'optional': {
'environment': { 'environment': {
@ -164,8 +164,7 @@ SPEC_DEVICE_TRANS_MAP: dict = {
'continue-sweep', 'continue-sweep',
'stop-and-gocharge' 'stop-and-gocharge'
} }
}, }
} }
}, },
'optional': { 'optional': {
@ -178,9 +177,9 @@ SPEC_DEVICE_TRANS_MAP: dict = {
'required': { 'required': {
'properties': { 'properties': {
'battery-level': {'read'} 'battery-level': {'read'}
}, }
} }
}, }
}, },
'entity': 'vacuum' 'entity': 'vacuum'
}, },
@ -196,7 +195,7 @@ SPEC_DEVICE_TRANS_MAP: dict = {
}, },
'optional': { 'optional': {
'properties': {'target-humidity'} 'properties': {'target-humidity'}
}, }
} }
}, },
'optional': { 'optional': {
@ -237,7 +236,7 @@ SPEC_DEVICE_TRANS_MAP: dict = {
'properties': { 'properties': {
'target-temperature', 'mode', 'fan-level', 'target-temperature', 'mode', 'fan-level',
'temperature'} 'temperature'}
}, }
} }
}, },
'optional': { 'optional': {
@ -246,7 +245,7 @@ SPEC_DEVICE_TRANS_MAP: dict = {
'optional': { 'optional': {
'properties': {'temperature', 'relative-humidity'} 'properties': {'temperature', 'relative-humidity'}
} }
}, }
}, },
'entity': 'thermostat' 'entity': 'thermostat'
}, },
@ -260,7 +259,7 @@ SPEC_DEVICE_TRANS_MAP: dict = {
}, },
'optional': { 'optional': {
'properties': {'target-temperature', 'heat-level'} 'properties': {'target-temperature', 'heat-level'}
}, }
} }
}, },
'optional': { 'optional': {
@ -269,20 +268,21 @@ SPEC_DEVICE_TRANS_MAP: dict = {
'optional': { 'optional': {
'properties': {'temperature', 'relative-humidity'} 'properties': {'temperature', 'relative-humidity'}
} }
}, }
}, },
'entity': 'heater' 'entity': 'heater'
}, },
'bath-heater': { 'bath-heater': {
'required': { 'required': {
'ptc-bath-heater': { 'ptc-bath-heater': {
'required': {}, 'required': {
'optional': {
'properties': { 'properties': {
'target-temperature', 'heat-level', 'mode':{'read', 'write'}
'temperature', 'mode'
} }
}, },
'optional': {
'properties': {'target-temperature', 'temperature'}
}
} }
}, },
'optional': { 'optional': {
@ -292,7 +292,13 @@ SPEC_DEVICE_TRANS_MAP: dict = {
'properties': { 'properties': {
'on', 'fan-level', 'horizontal-swing', 'vertical-swing' 'on', 'fan-level', 'horizontal-swing', 'vertical-swing'
} }
}, }
},
'environment': {
'required': {},
'optional': {
'properties': {'temperature'}
}
} }
}, },
'entity': 'bath-heater', 'entity': 'bath-heater',
@ -308,7 +314,7 @@ SPEC_DEVICE_TRANS_MAP: dict = {
}, },
'optional': { 'optional': {
'properties': {'mode', 'temperature'} 'properties': {'mode', 'temperature'}
}, }
} }
}, },
'optional': {}, 'optional': {},
@ -400,7 +406,7 @@ SPEC_SERVICE_TRANS_MAP: dict = {
}, },
'optional': { 'optional': {
'properties': { 'properties': {
'motor-control', 'status', 'current-position', 'target-position' 'status', 'current-position', 'target-position'
} }
}, },
'entity': 'cover' 'entity': 'cover'