Merge branch 'main' into main

This commit is contained in:
Vadym
2024-08-22 18:23:28 +03:00
committed by GitHub
49 changed files with 17484 additions and 261 deletions
+32 -10
View File
@@ -13,7 +13,8 @@ from pyhon.parameter.base import HonParameter
from pyhon.parameter.range import HonParameterRange
from .const import DOMAIN
from .hon import HonEntity, unique_entities
from .entity import HonEntity
from .util import unique_entities
_LOGGER = logging.getLogger(__name__)
@@ -273,6 +274,12 @@ SWITCHES: dict[str, tuple[SwitchEntityDescription, ...]] = {
icon="mdi:volume-off",
translation_key="buzzer",
),
HonConfigSwitchEntityDescription(
key="startProgram.tabStatus",
name="Tab Status",
icon="mdi:silverware-clean",
# translation_key="buzzer",
),
),
"AC": (
HonSwitchEntityDescription(
@@ -393,6 +400,20 @@ SWITCHES: dict[str, tuple[SwitchEntityDescription, ...]] = {
to_sync=True,
),
),
"FRE": (
HonSwitchEntityDescription(
key="quickModeZ2",
name="Super Freeze",
icon="mdi:snowflake-variant",
translation_key="super_freeze",
),
HonSwitchEntityDescription(
key="quickModeZ1",
name="Super Cool",
icon="mdi:snowflake",
translation_key="super_cool",
),
),
}
SWITCHES["WD"] = unique_entities(SWITCHES["WD"], SWITCHES["WM"])
@@ -404,7 +425,7 @@ async def async_setup_entry(
) -> None:
entities = []
entity: HonConfigSwitchEntity | HonControlSwitchEntity | HonSwitchEntity
for device in hass.data[DOMAIN][entry.unique_id].appliances:
for device in hass.data[DOMAIN][entry.unique_id]["hon"].appliances:
for description in SWITCHES.get(device.appliance_type, []):
if isinstance(description, HonConfigSwitchEntityDescription):
if description.key not in device.available_settings:
@@ -424,7 +445,6 @@ async def async_setup_entry(
entity = HonSwitchEntity(hass, entry, device, description)
else:
continue
await entity.coordinator.async_config_entry_first_refresh()
entities.append(entity)
async_add_entities(entities)
@@ -445,7 +465,7 @@ class HonSwitchEntity(HonEntity, SwitchEntity):
setting.value = setting.max if isinstance(setting, HonParameterRange) else 1
self.async_write_ha_state()
await self._device.commands["settings"].send()
await self.coordinator.async_refresh()
self.coordinator.async_set_updated_data({})
async def async_turn_off(self, **kwargs: Any) -> None:
setting = self._device.settings[f"settings.{self.entity_description.key}"]
@@ -454,7 +474,7 @@ class HonSwitchEntity(HonEntity, SwitchEntity):
setting.value = setting.min if isinstance(setting, HonParameterRange) else 0
self.async_write_ha_state()
await self._device.commands["settings"].send()
await self.coordinator.async_refresh()
self.coordinator.async_set_updated_data({})
@property
def available(self) -> bool:
@@ -490,7 +510,8 @@ class HonControlSwitchEntity(HonEntity, SwitchEntity):
async def async_turn_on(self, **kwargs: Any) -> None:
desc = self.entity_description
self._device.sync_command(desc.turn_on_key, "settings", desc.to_sync)
await self.coordinator.async_refresh()
//await self.coordinator.async_refresh()
self.coordinator.async_set_updated_data({})
command = self._device.commands[desc.turn_on_key]
await command.send(desc.only_mandatory_parameters)
self._device.attributes[desc.key] = desc.on_value
@@ -499,7 +520,8 @@ class HonControlSwitchEntity(HonEntity, SwitchEntity):
async def async_turn_off(self, **kwargs: Any) -> None:
desc = self.entity_description
self._device.sync_command(desc.turn_off_key, "settings", desc.to_sync)
await self.coordinator.async_refresh()
//await self.coordinator.async_refresh()
self.coordinator.async_set_updated_data({})
command = self._device.commands[desc.turn_off_key]
await command.send(desc.only_mandatory_parameters)
self._device.attributes[desc.key] = desc.off_value
@@ -511,7 +533,7 @@ class HonControlSwitchEntity(HonEntity, SwitchEntity):
return (
super().available
and int(self._device.get("remoteCtrValid", 1)) == 1
and self._device.get("attributes.lastConnEvent.category") != "DISCONNECTED"
and self._device.connection
)
@property
@@ -545,16 +567,16 @@ class HonConfigSwitchEntity(HonEntity, SwitchEntity):
if type(setting) == HonParameter:
return
setting.value = setting.max if isinstance(setting, HonParameterRange) else "1"
self.coordinator.async_set_updated_data({})
self.async_write_ha_state()
await self.coordinator.async_refresh()
async def async_turn_off(self, **kwargs: Any) -> None:
setting = self._device.settings[self.entity_description.key]
if type(setting) == HonParameter:
return
setting.value = setting.min if isinstance(setting, HonParameterRange) else "0"
self.coordinator.async_set_updated_data({})
self.async_write_ha_state()
await self.coordinator.async_refresh()
@callback
def _handle_coordinator_update(self, update: bool = True) -> None: