Add event platform to LG ThinQ integration (#125800)
* Add event platform to LG ThinQ integration * Add error and notification translations * Update event.py * Fix translations * Fix --------- Co-authored-by: jangwon.lee <jangwon.lee@lge.com> Co-authored-by: Joostlek <joostlek@outlook.com>
This commit is contained in:
parent
0177313595
commit
527cd368f0
4 changed files with 243 additions and 2 deletions
|
@ -20,7 +20,12 @@ from .coordinator import DeviceDataUpdateCoordinator, async_setup_device_coordin
|
|||
|
||||
type ThinqConfigEntry = ConfigEntry[dict[str, DeviceDataUpdateCoordinator]]
|
||||
|
||||
PLATFORMS = [Platform.BINARY_SENSOR, Platform.NUMBER, Platform.SWITCH]
|
||||
PLATFORMS = [
|
||||
Platform.BINARY_SENSOR,
|
||||
Platform.EVENT,
|
||||
Platform.NUMBER,
|
||||
Platform.SWITCH,
|
||||
]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
|
120
homeassistant/components/lg_thinq/event.py
Normal file
120
homeassistant/components/lg_thinq/event.py
Normal file
|
@ -0,0 +1,120 @@
|
|||
"""Support for event entity."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from thinqconnect import DeviceType
|
||||
from thinqconnect.integration import ActiveMode, ThinQPropertyEx
|
||||
|
||||
from homeassistant.components.event import EventEntity, EventEntityDescription
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import ThinqConfigEntry
|
||||
from .coordinator import DeviceDataUpdateCoordinator
|
||||
from .entity import ThinQEntity
|
||||
|
||||
NOTIFICATION_EVENT_DESC = EventEntityDescription(
|
||||
key=ThinQPropertyEx.NOTIFICATION,
|
||||
translation_key=ThinQPropertyEx.NOTIFICATION,
|
||||
)
|
||||
ERROR_EVENT_DESC = EventEntityDescription(
|
||||
key=ThinQPropertyEx.ERROR,
|
||||
translation_key=ThinQPropertyEx.ERROR,
|
||||
)
|
||||
ALL_EVENTS: tuple[EventEntityDescription, ...] = (
|
||||
ERROR_EVENT_DESC,
|
||||
NOTIFICATION_EVENT_DESC,
|
||||
)
|
||||
DEVICE_TYPE_EVENT_MAP: dict[DeviceType, tuple[EventEntityDescription, ...]] = {
|
||||
DeviceType.AIR_CONDITIONER: (NOTIFICATION_EVENT_DESC,),
|
||||
DeviceType.AIR_PURIFIER_FAN: (NOTIFICATION_EVENT_DESC,),
|
||||
DeviceType.AIR_PURIFIER: (NOTIFICATION_EVENT_DESC,),
|
||||
DeviceType.DEHUMIDIFIER: (NOTIFICATION_EVENT_DESC,),
|
||||
DeviceType.DISH_WASHER: ALL_EVENTS,
|
||||
DeviceType.DRYER: ALL_EVENTS,
|
||||
DeviceType.HUMIDIFIER: (NOTIFICATION_EVENT_DESC,),
|
||||
DeviceType.KIMCHI_REFRIGERATOR: (NOTIFICATION_EVENT_DESC,),
|
||||
DeviceType.MICROWAVE_OVEN: (NOTIFICATION_EVENT_DESC,),
|
||||
DeviceType.OVEN: (NOTIFICATION_EVENT_DESC,),
|
||||
DeviceType.REFRIGERATOR: (NOTIFICATION_EVENT_DESC,),
|
||||
DeviceType.ROBOT_CLEANER: ALL_EVENTS,
|
||||
DeviceType.STICK_CLEANER: (NOTIFICATION_EVENT_DESC,),
|
||||
DeviceType.STYLER: ALL_EVENTS,
|
||||
DeviceType.WASHCOMBO_MAIN: ALL_EVENTS,
|
||||
DeviceType.WASHCOMBO_MINI: ALL_EVENTS,
|
||||
DeviceType.WASHER: ALL_EVENTS,
|
||||
DeviceType.WASHTOWER_DRYER: ALL_EVENTS,
|
||||
DeviceType.WASHTOWER: ALL_EVENTS,
|
||||
DeviceType.WASHTOWER_WASHER: ALL_EVENTS,
|
||||
DeviceType.WINE_CELLAR: (NOTIFICATION_EVENT_DESC,),
|
||||
}
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ThinqConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up an entry for event platform."""
|
||||
entities: list[ThinQEventEntity] = []
|
||||
for coordinator in entry.runtime_data.values():
|
||||
if (
|
||||
descriptions := DEVICE_TYPE_EVENT_MAP.get(
|
||||
coordinator.api.device.device_type
|
||||
)
|
||||
) is not None:
|
||||
for description in descriptions:
|
||||
entities.extend(
|
||||
ThinQEventEntity(coordinator, description, property_id)
|
||||
for property_id in coordinator.api.get_active_idx(
|
||||
description.key, ActiveMode.READ_ONLY
|
||||
)
|
||||
)
|
||||
|
||||
if entities:
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class ThinQEventEntity(ThinQEntity, EventEntity):
|
||||
"""Represent an thinq event platform."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: DeviceDataUpdateCoordinator,
|
||||
entity_description: EventEntityDescription,
|
||||
property_id: str,
|
||||
) -> None:
|
||||
"""Initialize an event platform."""
|
||||
super().__init__(coordinator, entity_description, property_id)
|
||||
|
||||
# For event types.
|
||||
self._attr_event_types = self.data.options
|
||||
|
||||
def _update_status(self) -> None:
|
||||
"""Update status itself."""
|
||||
super()._update_status()
|
||||
|
||||
# Handle an event.
|
||||
if (value := self.data.value) is None or value not in self.event_types:
|
||||
return
|
||||
|
||||
self._async_handle_update(value)
|
||||
if self.entity_description.key == ThinQPropertyEx.NOTIFICATION:
|
||||
self.coordinator.api.update_notification(None)
|
||||
|
||||
_LOGGER.warning(
|
||||
"[%s:%s] update status:%s, event_types:%s",
|
||||
self.coordinator.device_name,
|
||||
self.property_id,
|
||||
self.data.value,
|
||||
self.event_types,
|
||||
)
|
||||
|
||||
def _async_handle_update(self, value: str) -> None:
|
||||
"""Handle the event."""
|
||||
self._trigger_event(value)
|
||||
self.async_write_ha_state()
|
|
@ -40,6 +40,14 @@
|
|||
"default": "mdi:air-filter"
|
||||
}
|
||||
},
|
||||
"event": {
|
||||
"error": {
|
||||
"default": "mdi:alert-circle-outline"
|
||||
},
|
||||
"notification": {
|
||||
"default": "mdi:message-badge-outline"
|
||||
}
|
||||
},
|
||||
"number": {
|
||||
"target_temperature": {
|
||||
"default": "mdi:thermometer"
|
||||
|
|
|
@ -59,9 +59,117 @@
|
|||
"name": "Fresh air filter"
|
||||
}
|
||||
},
|
||||
"event": {
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"state_attributes": {
|
||||
"event_type": {
|
||||
"state": {
|
||||
"block_error": "Cleaning has stopped. Check for obstacles",
|
||||
"brush_error": "Moving brush has a problem",
|
||||
"bubble_error": "Bubble error",
|
||||
"child_lock_active_error": "Child lock",
|
||||
"cliff_error": "Fall prevention sensor has an error",
|
||||
"clutch_error": "Clutch error",
|
||||
"compressor_error": "Compressor error",
|
||||
"dispensing_error": "Dispensor error",
|
||||
"door_close_error": "Door closed error",
|
||||
"door_lock_error": "Door lock error",
|
||||
"door_open_error": "Door open",
|
||||
"door_sensor_error": "Door sensor error",
|
||||
"drainmotor_error": "Drain error",
|
||||
"dust_full_error": "Dust bin is full and needs to be emptied",
|
||||
"empty_water_alert_error": "Empty water",
|
||||
"fan_motor_error": "Fan lock error",
|
||||
"filter_clogging_error": "Filter error",
|
||||
"frozen_error": "Freezing detection error",
|
||||
"heater_circuit_error": "Heater circuit failure",
|
||||
"high_power_supply_error": "Power supply error",
|
||||
"high_temperature_detection_error": "High-temperature error",
|
||||
"inner_lid_open_error": "Lid open error",
|
||||
"ir_sensor_error": "IR sensor error",
|
||||
"le_error": "LE error",
|
||||
"le2_error": "LE2 error",
|
||||
"left_wheel_error": "Left wheel has a problem",
|
||||
"locked_motor_error": "Driver motor error",
|
||||
"mop_error": "Cannot operate properly without the mop attached",
|
||||
"motor_error": "Motor trouble",
|
||||
"motor_lock_error": "Motor lock error",
|
||||
"move_error": "The wheels are not touching the floor",
|
||||
"need_water_drain": "[%key:component::lg_thinq::entity::event::error::state_attributes::event_type::state::empty_water_alert_error%]",
|
||||
"need_water_replenishment": "Fill water",
|
||||
"no_battery_error": "Robot cleaner's battery is low",
|
||||
"no_dust_bin_error": "Dust bin is not installed",
|
||||
"no_filter_error": "[%key:component::lg_thinq::entity::event::error::state_attributes::event_type::state::filter_clogging_error%]",
|
||||
"out_of_balance_error": "Out of balance load",
|
||||
"overfill_error": "Overfill error",
|
||||
"part_malfunction_error": "AIE error",
|
||||
"power_code_connection_error": "Power cord connection error",
|
||||
"power_fail_error": "Power failure",
|
||||
"right_wheel_error": "Right wheel has a problem",
|
||||
"stack_error": "Stacking error",
|
||||
"steam_heat_error": "Steam heater error",
|
||||
"suction_blocked_error": "Suction motor is clogged",
|
||||
"temperature_sensor_error": "Thermistor error",
|
||||
"time_to_run_the_tub_clean_cycle_error": "Tub clean recommendation",
|
||||
"timeout_error": "Timeout error",
|
||||
"turbidity_sensor_error": "turbidity sensor error",
|
||||
"unable_to_lock_error": "Door lock error",
|
||||
"unbalanced_load_error": "[%key:component::lg_thinq::entity::event::error::state_attributes::event_type::state::out_of_balance_error%]",
|
||||
"unknown_error": "Product requires attention",
|
||||
"vibration_sensor_error": "Vibration sensor error",
|
||||
"water_drain_error": "Water drain error",
|
||||
"water_leakage_error": "Water leakage problem",
|
||||
"water_leaks_error": "[%key:component::lg_thinq::entity::event::error::state_attributes::event_type::state::water_leakage_error%]",
|
||||
"water_level_sensor_error": "Water sensor error",
|
||||
"water_supply_error": "Water supply error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"notification": {
|
||||
"name": "Notification",
|
||||
"state_attributes": {
|
||||
"event_type": {
|
||||
"state": {
|
||||
"charging_is_complete": "Charging is completed",
|
||||
"cleaning_is_complete": "Cycle is finished",
|
||||
"cleaning_is_completed": "Cleaning is completed",
|
||||
"cleaning_is_failed": "Cleaning has failed",
|
||||
"cooking_is_complete": "Turned off",
|
||||
"door_is_open": "The door is open",
|
||||
"drying_failed": "An error has occurred in the dryer",
|
||||
"drying_is_complete": "Drying is completed",
|
||||
"error_during_cleaning": "Cleaning stopped due to an error",
|
||||
"error_during_washing": "An error has occurred in the washing machine",
|
||||
"error_has_occurred": "An error has occurred",
|
||||
"frozen_is_complete": "Ice plus is done",
|
||||
"homeguard_is_stopped": "Home guard has stopped",
|
||||
"lack_of_water": "There is no water in the water tank",
|
||||
"motion_is_detected": "Photograph is sent as movement is detected during home guard",
|
||||
"need_to_check_location": "Location check is required",
|
||||
"pollution_is_high": "Air status is rapidly becoming bad",
|
||||
"preheating_is_complete": "Preheating is done",
|
||||
"rinse_is_not_enough": "Add rinse aid for better drying performance",
|
||||
"salt_refill_is_needed": "Add salt for better softening performance",
|
||||
"scheduled_cleaning_starts": "Scheduled cleaning starts",
|
||||
"styling_is_complete": "Styling is completed",
|
||||
"time_to_change_filter": "It is time to replace the filter",
|
||||
"time_to_change_water_filter": "You need to replace water filter",
|
||||
"time_to_clean": "Need to selfcleaning",
|
||||
"time_to_clean_filter": "It is time to clean the filter",
|
||||
"timer_is_complete": "Timer has been completed",
|
||||
"washing_is_complete": "Washing is completed",
|
||||
"water_is_full": "Water is full",
|
||||
"water_leak_has_occurred": "The dishwasher has detected a water leak"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"number": {
|
||||
"target_temperature": {
|
||||
"name": "Temperature"
|
||||
"name": "[%key:component::sensor::entity_component::temperature::name%]"
|
||||
},
|
||||
"target_temperature_for_location": {
|
||||
"name": "{location} temperature"
|
||||
|
|
Loading…
Add table
Reference in a new issue