Add number input for apsystems (#118825)

* Add number input for apsystems

* Exclude number from apsystems from coverage

* Remove unnecessary int-float conversion in apsystems number

* Remove unnecessary int-float conversion in apsystems number and redundant and single use variables

* Add translation for apsystems number
This commit is contained in:
Marlon 2024-06-17 10:31:21 +02:00 committed by GitHub
parent 8556f3e7c8
commit 496338fa4e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 57 additions and 1 deletions

View File

@ -90,6 +90,7 @@ omit =
homeassistant/components/apsystems/__init__.py
homeassistant/components/apsystems/coordinator.py
homeassistant/components/apsystems/entity.py
homeassistant/components/apsystems/number.py
homeassistant/components/apsystems/sensor.py
homeassistant/components/aqualogic/*
homeassistant/components/aquostv/media_player.py

View File

@ -12,7 +12,7 @@ from homeassistant.core import HomeAssistant
from .coordinator import ApSystemsDataCoordinator
PLATFORMS: list[Platform] = [Platform.SENSOR]
PLATFORMS: list[Platform] = [Platform.NUMBER, Platform.SENSOR]
@dataclass

View File

@ -0,0 +1,52 @@
"""The output limit which can be set in the APsystems local API integration."""
from __future__ import annotations
from homeassistant.components.number import NumberDeviceClass, NumberEntity, NumberMode
from homeassistant.const import UnitOfPower
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import DiscoveryInfoType
from . import ApSystemsConfigEntry, ApSystemsData
from .entity import ApSystemsEntity
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ApSystemsConfigEntry,
add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the sensor platform."""
add_entities([ApSystemsMaxOutputNumber(config_entry.runtime_data)])
class ApSystemsMaxOutputNumber(ApSystemsEntity, NumberEntity):
"""Base sensor to be used with description."""
_attr_native_max_value = 800
_attr_native_min_value = 30
_attr_native_step = 1
_attr_device_class = NumberDeviceClass.POWER
_attr_mode = NumberMode.BOX
_attr_native_unit_of_measurement = UnitOfPower.WATT
_attr_translation_key = "max_output"
def __init__(
self,
data: ApSystemsData,
) -> None:
"""Initialize the sensor."""
super().__init__(data)
self._api = data.coordinator.api
self._attr_unique_id = f"{data.device_id}_output_limit"
async def async_update(self) -> None:
"""Set the state with the value fetched from the inverter."""
self._attr_native_value = await self._api.get_max_power()
async def async_set_native_value(self, value: float) -> None:
"""Set the desired output power."""
self._attr_native_value = await self._api.set_max_power(int(value))

View File

@ -25,6 +25,9 @@
"today_production": { "name": "Production of today" },
"today_production_p1": { "name": "Production of today from P1" },
"today_production_p2": { "name": "Production of today from P2" }
},
"number": {
"max_output": { "name": "Max output" }
}
}
}