1 """Base class for ThinQ entities."""
3 from __future__
import annotations
5 from collections.abc
import Callable, Coroutine
9 from thinqconnect
import ThinQAPIException
10 from thinqconnect.devices.const
import Location
11 from thinqconnect.integration
import PropertyState
20 from .const
import COMPANY, DOMAIN
21 from .coordinator
import DeviceDataUpdateCoordinator
23 _LOGGER = logging.getLogger(__name__)
25 EMPTY_STATE = PropertyState()
27 UNIT_CONVERSION_MAP: dict[str, str] = {
28 "F": UnitOfTemperature.FAHRENHEIT,
29 "C": UnitOfTemperature.CELSIUS,
34 """The base implementation of all lg thinq entities."""
36 _attr_has_entity_name =
True
40 coordinator: DeviceDataUpdateCoordinator,
41 entity_description: EntityDescription,
44 """Initialize an entity."""
52 identifiers={(DOMAIN, coordinator.unique_id)},
54 model=f
"{coordinator.api.device.model_name} ({self.coordinator.api.device.device_type})",
55 name=coordinator.device_name,
57 self.
_attr_unique_id_attr_unique_id = f
"{coordinator.unique_id}_{self.property_id}"
65 f
"{entity_description.translation_key}_for_location"
69 def data(self) -> PropertyState:
70 """Return the state data of entity."""
71 return self.coordinator.data.get(self.
property_idproperty_id, EMPTY_STATE)
74 """Convert thinq unit string to HA unit string."""
78 return UNIT_CONVERSION_MAP.get(unit)
81 """Update status itself.
83 All inherited classes can update their own status in here.
88 """Handle updated data from the coordinator."""
90 self.async_write_ha_state()
93 """Call when entity is added to hass."""
99 target: Coroutine[Any, Any, Any],
100 on_fail_method: Callable[[],
None] |
None =
None,
102 """Call the given api and handle exception."""
105 except ThinQAPIException
as exc:
109 exc.message, translation_domain=DOMAIN, translation_key=exc.code
111 except ValueError
as exc:
None async_call_api(self, Coroutine[Any, Any, Any] target, Callable[[], None]|None on_fail_method=None)
None _update_status(self)
None __init__(self, DeviceDataUpdateCoordinator coordinator, EntityDescription entity_description, str property_id)
None _handle_coordinator_update(self)
None async_added_to_hass(self)
_attr_translation_placeholders
str|None _get_unit_of_measurement(self, str|None unit)