mirror of
https://github.com/Andre0512/hon.git
synced 2024-12-22 10:45:30 +00:00
Fix many bugs
This commit is contained in:
parent
88c76b8056
commit
075d34b5e2
|
@ -26,14 +26,14 @@ class HonBinarySensorEntityDescription(HonBinarySensorEntityDescriptionMixin, Bi
|
|||
BINARY_SENSORS: dict[str, tuple[HonBinarySensorEntityDescription, ...]] = {
|
||||
"WM": (
|
||||
HonBinarySensorEntityDescription(
|
||||
key="lastConnEvent.category",
|
||||
key="attributes.lastConnEvent.category",
|
||||
name="Connection",
|
||||
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
||||
on_value="CONNECTED",
|
||||
),
|
||||
HonBinarySensorEntityDescription(
|
||||
key="doorLockStatus",
|
||||
name="Door Locked",
|
||||
name="Door",
|
||||
device_class=BinarySensorDeviceClass.DOOR,
|
||||
on_value="0",
|
||||
),
|
||||
|
@ -53,9 +53,9 @@ async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> Non
|
|||
hass.data[DOMAIN]["coordinators"][device.mac_address] = coordinator
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
if descriptions := BINARY_SENSORS.get(device.appliance_type_name):
|
||||
if descriptions := BINARY_SENSORS.get(device.appliance_type):
|
||||
for description in descriptions:
|
||||
if not device.data.get(description.key):
|
||||
if not device.get(description.key):
|
||||
_LOGGER.info("Can't setup %s", description.key)
|
||||
continue
|
||||
appliances.extend([
|
||||
|
@ -78,9 +78,9 @@ class HonBinarySensorEntity(HonEntity, BinarySensorEntity):
|
|||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
return self._device.data.get(self.entity_description.key, "") == self.entity_description.on_value
|
||||
return self._device.get(self.entity_description.key, "") == self.entity_description.on_value
|
||||
|
||||
@callback
|
||||
def _handle_coordinator_update(self):
|
||||
self._attr_native_value = self._device.data.get(self.entity_description.key, "")
|
||||
self._attr_native_value = self._device.get(self.entity_description.key, "") == self.entity_description.on_value
|
||||
self.async_write_ha_state()
|
||||
|
|
|
@ -9,16 +9,16 @@ from .hon import HonCoordinator, HonEntity
|
|||
|
||||
BUTTONS: dict[str, tuple[ButtonEntityDescription, ...]] = {
|
||||
"WM": (
|
||||
ButtonEntityDescription(
|
||||
key="pauseProgram",
|
||||
name="Pause Program",
|
||||
icon="mdi:pause",
|
||||
),
|
||||
ButtonEntityDescription(
|
||||
key="resumeProgram",
|
||||
name="Resume Program",
|
||||
icon="mdi:play-pause",
|
||||
),
|
||||
# ButtonEntityDescription(
|
||||
# key="pauseProgram",
|
||||
# name="Pause Program",
|
||||
# icon="mdi:pause",
|
||||
# ),
|
||||
# ButtonEntityDescription(
|
||||
# key="resumeProgram",
|
||||
# name="Resume Program",
|
||||
# icon="mdi:play-pause",
|
||||
# ),
|
||||
),
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> Non
|
|||
hass.data[DOMAIN]["coordinators"][device.mac_address] = coordinator
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
if descriptions := BUTTONS.get(device.appliance_type_name):
|
||||
if descriptions := BUTTONS.get(device.appliance_type):
|
||||
for description in descriptions:
|
||||
if not device.commands.get(description.key):
|
||||
continue
|
||||
|
|
|
@ -28,10 +28,10 @@ class HonEntity(CoordinatorEntity):
|
|||
def device_info(self):
|
||||
return DeviceInfo(
|
||||
identifiers={(DOMAIN, self._device.mac_address)},
|
||||
manufacturer=self._device.brand,
|
||||
manufacturer=self._device.get("brand", ""),
|
||||
name=self._device.nick_name if self._device.nick_name else self._device.model_name,
|
||||
model=self._device.model_name,
|
||||
sw_version=self._device.fw_version,
|
||||
sw_version=self._device.get("fwVersion", ""),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"documentation": "https://github.com/Andre0512/hon/",
|
||||
"iot_class": "cloud_polling",
|
||||
"issue_tracker": "https://github.com/Andre0512/hon/issues",
|
||||
"requirements": ["pyhOn==0.2.4"],
|
||||
"version": "0.1.1"
|
||||
"requirements": ["pyhOn==0.3.3"],
|
||||
"version": "0.2.0"
|
||||
}
|
||||
|
||||
|
|
|
@ -20,19 +20,20 @@ NUMBERS: dict[str, tuple[NumberEntityDescription, ...]] = {
|
|||
NumberEntityDescription(
|
||||
key="startProgram.delayTime",
|
||||
name="Delay Time",
|
||||
icon="mdi:timer",
|
||||
icon="mdi:timer-plus",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
native_unit_of_measurement=UnitOfTime.MINUTES
|
||||
),
|
||||
NumberEntityDescription(
|
||||
key="startProgram.rinseIterations",
|
||||
name="Rinse Iterations",
|
||||
icon="mdi:rotate-right",
|
||||
entity_category=EntityCategory.CONFIG
|
||||
),
|
||||
NumberEntityDescription(
|
||||
key="startProgram.mainWashTime",
|
||||
name="Main Wash Time",
|
||||
icon="mdi:timer",
|
||||
icon="mdi:clock-start",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
native_unit_of_measurement=UnitOfTime.MINUTES
|
||||
),
|
||||
|
@ -52,7 +53,7 @@ async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> Non
|
|||
hass.data[DOMAIN]["coordinators"][device.mac_address] = coordinator
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
if descriptions := NUMBERS.get(device.appliance_type_name):
|
||||
if descriptions := NUMBERS.get(device.appliance_type):
|
||||
for description in descriptions:
|
||||
appliances.extend([
|
||||
HonNumberEntity(hass, coordinator, entry, device, description)]
|
||||
|
@ -66,6 +67,7 @@ class HonNumberEntity(HonEntity, NumberEntity):
|
|||
super().__init__(hass, entry, coordinator, device)
|
||||
|
||||
self._coordinator = coordinator
|
||||
self._device = device
|
||||
self._data = device.settings[description.key]
|
||||
self.entity_description = description
|
||||
self._attr_unique_id = f"{super().unique_id}{description.key}"
|
||||
|
@ -77,18 +79,18 @@ class HonNumberEntity(HonEntity, NumberEntity):
|
|||
|
||||
@property
|
||||
def native_value(self) -> float | None:
|
||||
return self._data.value
|
||||
return self._device.get(self.entity_description.key)
|
||||
|
||||
async def async_set_native_value(self, value: float) -> None:
|
||||
self._data.value = value
|
||||
self._device.settings[self.entity_description.key].value = value
|
||||
await self.coordinator.async_request_refresh()
|
||||
|
||||
@callback
|
||||
def _handle_coordinator_update(self):
|
||||
self._data = self._device.settings[self.entity_description.key]
|
||||
if isinstance(self._data, HonParameterRange):
|
||||
self._attr_native_max_value = self._data.max
|
||||
self._attr_native_min_value = self._data.min
|
||||
self._attr_native_step = self._data.step
|
||||
self._attr_native_value = self._data.value
|
||||
setting = self._device.settings[self.entity_description.key]
|
||||
if isinstance(setting, HonParameterRange):
|
||||
self._attr_native_max_value = setting.max
|
||||
self._attr_native_min_value = setting.min
|
||||
self._attr_native_step = setting.step
|
||||
self._attr_native_value = setting.value
|
||||
self.async_write_ha_state()
|
||||
|
|
|
@ -50,9 +50,9 @@ async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> Non
|
|||
hass.data[DOMAIN]["coordinators"][device.mac_address] = coordinator
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
if descriptions := SELECTS.get(device.appliance_type_name):
|
||||
if descriptions := SELECTS.get(device.appliance_type):
|
||||
for description in descriptions:
|
||||
if not device.data.get(description.key):
|
||||
if not device.get(description.key):
|
||||
continue
|
||||
appliances.extend([
|
||||
HonSelectEntity(hass, coordinator, entry, device, description)]
|
||||
|
@ -66,32 +66,31 @@ class HonSelectEntity(HonEntity, SelectEntity):
|
|||
|
||||
self._coordinator = coordinator
|
||||
self._device = device
|
||||
self._data = device.settings[description.key]
|
||||
self.entity_description = description
|
||||
self._attr_unique_id = f"{super().unique_id}{description.key}"
|
||||
|
||||
if not isinstance(self._data, HonParameterFixed):
|
||||
self._attr_options: list[str] = self._data.values
|
||||
if not isinstance(self._device.settings[description.key], HonParameterFixed):
|
||||
self._attr_options: list[str] = device.settings[description.key].values
|
||||
else:
|
||||
self._attr_options = [self._data.value]
|
||||
self._attr_options: list[str] = [device.settings[description.key].value]
|
||||
|
||||
@property
|
||||
def current_option(self) -> str | None:
|
||||
value = self._data.value
|
||||
value = self._device.settings[self.entity_description.key].value
|
||||
if value is None or value not in self._attr_options:
|
||||
return None
|
||||
return value
|
||||
|
||||
async def async_select_option(self, option: str) -> None:
|
||||
self._data.value = option
|
||||
self._device.settings[self.entity_description.key].value = option
|
||||
await self.coordinator.async_request_refresh()
|
||||
|
||||
@callback
|
||||
def _handle_coordinator_update(self):
|
||||
self._data = self._device.settings[self.entity_description.key]
|
||||
if not isinstance(self._data, HonParameterFixed):
|
||||
self._attr_options: list[str] = self._data.values
|
||||
setting = self._device.settings[self.entity_description.key]
|
||||
if not isinstance(self._device.settings[self.entity_description.key], HonParameterFixed):
|
||||
self._attr_options: list[str] = setting.values
|
||||
else:
|
||||
self._attr_options = [self._data.value]
|
||||
self._attr_native_value = self._data.value
|
||||
self._attr_options = [setting.value]
|
||||
self._attr_native_value = setting.value
|
||||
self.async_write_ha_state()
|
||||
|
|
|
@ -65,13 +65,13 @@ SENSORS: dict[str, tuple[SensorEntityDescription, ...]] = {
|
|||
),
|
||||
SensorEntityDescription(
|
||||
key="machMode",
|
||||
name="Machine Last Status",
|
||||
name="Machine Status",
|
||||
icon="mdi:information",
|
||||
translation_key="mode"
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="errors",
|
||||
name="Last Error",
|
||||
name="Error",
|
||||
icon="mdi:math-log",
|
||||
translation_key="errors"
|
||||
),
|
||||
|
@ -105,9 +105,9 @@ async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> Non
|
|||
hass.data[DOMAIN]["coordinators"][device.mac_address] = coordinator
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
if descriptions := SENSORS.get(device.appliance_type_name):
|
||||
if descriptions := SENSORS.get(device.appliance_type):
|
||||
for description in descriptions:
|
||||
if not device.data.get(description.key):
|
||||
if not device.get(description.key):
|
||||
continue
|
||||
appliances.extend([
|
||||
HonSensorEntity(hass, coordinator, entry, device, description)]
|
||||
|
@ -127,9 +127,9 @@ class HonSensorEntity(HonEntity, SensorEntity):
|
|||
|
||||
@property
|
||||
def native_value(self) -> StateType:
|
||||
return self._device.data.get(self.entity_description.key, "")
|
||||
return self._device.get(self.entity_description.key, "")
|
||||
|
||||
@callback
|
||||
def _handle_coordinator_update(self):
|
||||
self._attr_native_value = self._device.data.get(self.entity_description.key, "")
|
||||
self._attr_native_value = self._device.get(self.entity_description.key, "")
|
||||
self.async_write_ha_state()
|
||||
|
|
|
@ -27,20 +27,29 @@ class HonSwitchEntityDescription(HonSwitchEntityDescriptionMixin,
|
|||
SWITCHES: dict[str, tuple[HonSwitchEntityDescription, ...]] = {
|
||||
"WM": (
|
||||
HonSwitchEntityDescription(
|
||||
key="startProgram",
|
||||
name="Start Program",
|
||||
icon="mdi:play",
|
||||
key="active",
|
||||
name="Washing Machine",
|
||||
icon="mdi:washing-machine",
|
||||
turn_on_key="startProgram",
|
||||
turn_off_key="stopProgram",
|
||||
),
|
||||
HonSwitchEntityDescription(
|
||||
key="pause",
|
||||
name="Pause Washing Machine",
|
||||
icon="mdi:pause",
|
||||
turn_on_key="pauseProgram",
|
||||
turn_off_key="resumeProgram",
|
||||
),
|
||||
HonSwitchEntityDescription(
|
||||
key="startProgram.delayStatus",
|
||||
name="Delay Status",
|
||||
icon="mdi:timer-check",
|
||||
entity_category=EntityCategory.CONFIG
|
||||
),
|
||||
HonSwitchEntityDescription(
|
||||
key="startProgram.haier_SoakPrewashSelection",
|
||||
name="Soak Prewash Selection",
|
||||
icon="mdi:tshirt-crew",
|
||||
entity_category=EntityCategory.CONFIG
|
||||
),
|
||||
),
|
||||
|
@ -59,9 +68,9 @@ async def async_setup_entry(hass, entry: ConfigEntry, async_add_entities) -> Non
|
|||
hass.data[DOMAIN]["coordinators"][device.mac_address] = coordinator
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
if descriptions := SWITCHES.get(device.appliance_type_name):
|
||||
if descriptions := SWITCHES.get(device.appliance_type):
|
||||
for description in descriptions:
|
||||
if device.data.get(description.key) is not None or device.commands.get(description.key) is not None:
|
||||
if device.get(description.key) is not None or device.commands.get(description.key) is not None:
|
||||
appliances.extend([
|
||||
HonSwitchEntity(hass, coordinator, entry, device, description)]
|
||||
)
|
||||
|
@ -81,7 +90,7 @@ class HonSwitchEntity(HonEntity, SwitchEntity):
|
|||
|
||||
def available(self) -> bool:
|
||||
if self.entity_category == EntityCategory.CONFIG:
|
||||
return self._device.settings[self.entity_description.key].typology == "fixed"
|
||||
return self._device.settings[self.entity_description.key].typology != "fixed"
|
||||
return True
|
||||
|
||||
@property
|
||||
|
@ -90,7 +99,7 @@ class HonSwitchEntity(HonEntity, SwitchEntity):
|
|||
if self.entity_category == EntityCategory.CONFIG:
|
||||
setting = self._device.settings[self.entity_description.key]
|
||||
return setting.value == "1" or hasattr(setting, "min") and setting.value != setting.min
|
||||
return self._device.data.get(self.entity_description.key, "")
|
||||
return self._device.get(self.entity_description.key, False)
|
||||
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
if self.entity_category == EntityCategory.CONFIG:
|
||||
|
|
Loading…
Reference in a new issue