Home Assistant Unofficial Reference 2024.12.1
cover.py
Go to the documentation of this file.
1 """Support for Netatmo/Bubendorff covers."""
2 
3 from __future__ import annotations
4 
5 import logging
6 from typing import Any
7 
8 from pyatmo import modules as NaModules
9 
11  ATTR_POSITION,
12  CoverDeviceClass,
13  CoverEntity,
14  CoverEntityFeature,
15 )
16 from homeassistant.config_entries import ConfigEntry
17 from homeassistant.core import HomeAssistant, callback
18 from homeassistant.helpers.dispatcher import async_dispatcher_connect
19 from homeassistant.helpers.entity_platform import AddEntitiesCallback
20 
21 from .const import CONF_URL_CONTROL, NETATMO_CREATE_COVER
22 from .data_handler import HOME, SIGNAL_NAME, NetatmoDevice
23 from .entity import NetatmoModuleEntity
24 
25 _LOGGER = logging.getLogger(__name__)
26 
27 
29  hass: HomeAssistant,
30  entry: ConfigEntry,
31  async_add_entities: AddEntitiesCallback,
32 ) -> None:
33  """Set up the Netatmo cover platform."""
34 
35  @callback
36  def _create_entity(netatmo_device: NetatmoDevice) -> None:
37  entity = NetatmoCover(netatmo_device)
38  _LOGGER.debug("Adding cover %s", entity)
39  async_add_entities([entity])
40 
41  entry.async_on_unload(
42  async_dispatcher_connect(hass, NETATMO_CREATE_COVER, _create_entity)
43  )
44 
45 
47  """Representation of a Netatmo cover device."""
48 
49  _attr_supported_features = (
50  CoverEntityFeature.OPEN
51  | CoverEntityFeature.CLOSE
52  | CoverEntityFeature.STOP
53  | CoverEntityFeature.SET_POSITION
54  )
55  _attr_configuration_url = CONF_URL_CONTROL
56  _attr_device_class = CoverDeviceClass.SHUTTER
57  _attr_name = None
58  device: NaModules.Shutter
59 
60  def __init__(self, netatmo_device: NetatmoDevice) -> None:
61  """Initialize the Netatmo device."""
62  super().__init__(netatmo_device)
63 
64  self._attr_is_closed_attr_is_closed = self.devicedevice.current_position == 0
65 
66  self._signal_name_signal_name = f"{HOME}-{self.home.entity_id}"
67  self._publishers.extend(
68  [
69  {
70  "name": HOME,
71  "home_id": self.homehome.entity_id,
72  SIGNAL_NAME: self._signal_name_signal_name,
73  },
74  ]
75  )
76  self._attr_unique_id_attr_unique_id = f"{self.device.entity_id}-{self.device_type}"
77 
78  async def async_close_cover(self, **kwargs: Any) -> None:
79  """Close the cover."""
80  await self.devicedevice.async_close()
81  self._attr_is_closed_attr_is_closed = True
82  self.async_write_ha_stateasync_write_ha_state()
83 
84  async def async_open_cover(self, **kwargs: Any) -> None:
85  """Open the cover."""
86  await self.devicedevice.async_open()
87  self._attr_is_closed_attr_is_closed = False
88  self.async_write_ha_stateasync_write_ha_state()
89 
90  async def async_stop_cover(self, **kwargs: Any) -> None:
91  """Stop the cover."""
92  await self.devicedevice.async_stop()
93 
94  async def async_set_cover_position(self, **kwargs: Any) -> None:
95  """Move the cover shutter to a specific position."""
96  await self.devicedevice.async_set_target_position(kwargs[ATTR_POSITION])
97 
98  @callback
99  def async_update_callback(self) -> None:
100  """Update the entity's state."""
101  self._attr_is_closed_attr_is_closed = self.devicedevice.current_position == 0
102  self._attr_current_cover_position_attr_current_cover_position = self.devicedevice.current_position
None async_set_cover_position(self, **Any kwargs)
Definition: cover.py:94
None async_open_cover(self, **Any kwargs)
Definition: cover.py:84
None __init__(self, NetatmoDevice netatmo_device)
Definition: cover.py:60
None async_stop_cover(self, **Any kwargs)
Definition: cover.py:90
None async_close_cover(self, **Any kwargs)
Definition: cover.py:78
None async_stop(HomeAssistant hass)
Definition: discovery.py:694
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: cover.py:32
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)
Definition: dispatcher.py:103