Home Assistant Unofficial Reference 2024.12.1
number.py
Go to the documentation of this file.
1 """The output limit which can be set in the APsystems local API integration."""
2 
3 from __future__ import annotations
4 
5 from homeassistant.components.number import NumberDeviceClass, NumberEntity, NumberMode
6 from homeassistant.const import UnitOfPower
7 from homeassistant.core import HomeAssistant
8 from homeassistant.helpers.entity_platform import AddEntitiesCallback
9 from homeassistant.helpers.typing import DiscoveryInfoType
10 
11 from . import ApSystemsConfigEntry, ApSystemsData
12 from .entity import ApSystemsEntity
13 
14 
16  hass: HomeAssistant,
17  config_entry: ApSystemsConfigEntry,
18  add_entities: AddEntitiesCallback,
19  discovery_info: DiscoveryInfoType | None = None,
20 ) -> None:
21  """Set up the sensor platform."""
22 
23  add_entities([ApSystemsMaxOutputNumber(config_entry.runtime_data)])
24 
25 
27  """Base sensor to be used with description."""
28 
29  _attr_native_step = 1
30  _attr_device_class = NumberDeviceClass.POWER
31  _attr_mode = NumberMode.BOX
32  _attr_native_unit_of_measurement = UnitOfPower.WATT
33  _attr_translation_key = "max_output"
34 
35  def __init__(
36  self,
37  data: ApSystemsData,
38  ) -> None:
39  """Initialize the sensor."""
40  super().__init__(data)
41  self._api_api = data.coordinator.api
42  self._attr_unique_id_attr_unique_id = f"{data.device_id}_output_limit"
43  self._attr_native_max_value_attr_native_max_value = data.coordinator.api.max_power
44  self._attr_native_min_value_attr_native_min_value = data.coordinator.api.min_power
45 
46  async def async_update(self) -> None:
47  """Set the state with the value fetched from the inverter."""
48  self._attr_native_value_attr_native_value = await self._api_api.get_max_power()
49 
50  async def async_set_native_value(self, value: float) -> None:
51  """Set the desired output power."""
52  self._attr_native_value_attr_native_value = await self._api_api.set_max_power(int(value))
None async_setup_entry(HomeAssistant hass, ApSystemsConfigEntry config_entry, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)
Definition: number.py:20
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)