Home Assistant Unofficial Reference 2024.12.1
entity.py
Go to the documentation of this file.
1 """Support for SmartThings Cloud."""
2 
3 from __future__ import annotations
4 
5 from pysmartthings.device import DeviceEntity
6 
7 from homeassistant.helpers.device_registry import DeviceInfo
8 from homeassistant.helpers.dispatcher import async_dispatcher_connect
9 from homeassistant.helpers.entity import Entity
10 
11 from .const import DOMAIN, SIGNAL_SMARTTHINGS_UPDATE
12 
13 
15  """Defines a SmartThings entity."""
16 
17  _attr_should_poll = False
18 
19  def __init__(self, device: DeviceEntity) -> None:
20  """Initialize the instance."""
21  self._device_device = device
22  self._dispatcher_remove_dispatcher_remove = None
23  self._attr_name_attr_name = device.label
24  self._attr_unique_id_attr_unique_id = device.device_id
25  self._attr_device_info_attr_device_info = DeviceInfo(
26  configuration_url="https://account.smartthings.com",
27  identifiers={(DOMAIN, device.device_id)},
28  manufacturer=device.status.ocf_manufacturer_name,
29  model=device.status.ocf_model_number,
30  name=device.label,
31  hw_version=device.status.ocf_hardware_version,
32  sw_version=device.status.ocf_firmware_version,
33  )
34 
35  async def async_added_to_hass(self):
36  """Device added to hass."""
37 
38  async def async_update_state(devices):
39  """Update device state."""
40  if self._device_device.device_id in devices:
41  await self.async_update_ha_stateasync_update_ha_state(True)
42 
43  self._dispatcher_remove_dispatcher_remove = async_dispatcher_connect(
44  self.hasshass, SIGNAL_SMARTTHINGS_UPDATE, async_update_state
45  )
46 
47  async def async_will_remove_from_hass(self) -> None:
48  """Disconnect the device when removed."""
49  if self._dispatcher_remove_dispatcher_remove:
50  self._dispatcher_remove_dispatcher_remove()
None async_update_ha_state(self, bool force_refresh=False)
Definition: entity.py:942
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)
Definition: dispatcher.py:103