mirror of
https://github.com/home-assistant/core.git
synced 2026-09-07 05:52:27 +01:00
* bring back power switch * fix pylint issues * add SWITCH to platform list * improve run_on and turn_off functions * ruff formatting * replace _state with _attr_is_on * Update homeassistant/components/apsystems/switch.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * remove unused dependencies * Update homeassistant/components/apsystems/switch.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * use async functions from api * convert Api IntEnum Status Information to bool * add translation key * implement async_update again * replace finally with else * better handling of bool value * Update homeassistant/components/apsystems/switch.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/apsystems/switch.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * rename power switch to inverter switch * add test_number and test_switch module * remove test_number * Add mock entry for get_device_power_status * Add mock entry for get_device_power_status * Update test snapshots --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
"""The APsystems local API integration."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
|
|
from APsystemsEZ1 import APsystemsEZ1M
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.const import CONF_IP_ADDRESS, CONF_PORT, Platform
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from .const import DEFAULT_PORT
|
|
from .coordinator import ApSystemsDataCoordinator
|
|
|
|
PLATFORMS: list[Platform] = [Platform.NUMBER, Platform.SENSOR, Platform.SWITCH]
|
|
|
|
|
|
@dataclass
|
|
class ApSystemsData:
|
|
"""Store runtime data."""
|
|
|
|
coordinator: ApSystemsDataCoordinator
|
|
device_id: str
|
|
|
|
|
|
type ApSystemsConfigEntry = ConfigEntry[ApSystemsData]
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ApSystemsConfigEntry) -> bool:
|
|
"""Set up this integration using UI."""
|
|
api = APsystemsEZ1M(
|
|
ip_address=entry.data[CONF_IP_ADDRESS],
|
|
port=entry.data.get(CONF_PORT, DEFAULT_PORT),
|
|
timeout=8,
|
|
)
|
|
coordinator = ApSystemsDataCoordinator(hass, api)
|
|
await coordinator.async_config_entry_first_refresh()
|
|
assert entry.unique_id
|
|
entry.runtime_data = ApSystemsData(
|
|
coordinator=coordinator, device_id=entry.unique_id
|
|
)
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
|
|
|
return True
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
"""Unload a config entry."""
|
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|