Home Assistant Unofficial Reference 2024.12.1
text.py
Go to the documentation of this file.
1 """Provide a text platform for MySensors."""
2 
3 from __future__ import annotations
4 
5 from homeassistant.components.text import TextEntity
6 from homeassistant.config_entries import ConfigEntry
7 from homeassistant.const import Platform
8 from homeassistant.core import HomeAssistant, callback
9 from homeassistant.helpers.dispatcher import async_dispatcher_connect
10 from homeassistant.helpers.entity_platform import AddEntitiesCallback
11 
12 from . import setup_mysensors_platform
13 from .const import MYSENSORS_DISCOVERY, DiscoveryInfo
14 from .entity import MySensorsChildEntity
15 from .helpers import on_unload
16 
17 
19  hass: HomeAssistant,
20  config_entry: ConfigEntry,
21  async_add_entities: AddEntitiesCallback,
22 ) -> None:
23  """Set up this platform for a specific ConfigEntry(==Gateway)."""
24 
25  @callback
26  def async_discover(discovery_info: DiscoveryInfo) -> None:
27  """Discover and add a MySensors text entity."""
29  hass,
30  Platform.TEXT,
31  discovery_info,
32  MySensorsText,
33  async_add_entities=async_add_entities,
34  )
35 
36  on_unload(
37  hass,
38  config_entry.entry_id,
40  hass,
41  MYSENSORS_DISCOVERY.format(config_entry.entry_id, Platform.TEXT),
42  async_discover,
43  ),
44  )
45 
46 
48  """Representation of the value of a MySensors Text child node."""
49 
50  _attr_native_max = 25
51 
52  @property
53  def native_value(self) -> str | None:
54  """Return the value reported by the text."""
55  return self._values.get(self.value_type)
56 
57  async def async_set_value(self, value: str) -> None:
58  """Change the value."""
59  self.gateway.set_child_value(
60  self.node_id, self.child_id, self.value_type, value, ack=1
61  )
web.Response get(self, web.Request request, str config_key)
Definition: view.py:88
None on_unload(HomeAssistant hass, GatewayId gateway_id, Callable fnct)
Definition: helpers.py:45
None async_discover(DiscoveryInfo discovery_info)
Definition: sensor.py:217
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: text.py:22
list[MySensorsChildEntity]|None setup_mysensors_platform(HomeAssistant hass, Platform domain, DiscoveryInfo discovery_info, type[MySensorsChildEntity]|Mapping[SensorType, type[MySensorsChildEntity]] device_class,(tuple|None) device_args=None, Callable|None async_add_entities=None)
Definition: __init__.py:112
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)
Definition: dispatcher.py:103