1 """Support for APCUPSd via its Network Information Server (NIS)."""
3 from __future__
import annotations
6 from datetime
import timedelta
8 from typing
import Final
17 REQUEST_REFRESH_DEFAULT_IMMEDIATE,
18 DataUpdateCoordinator,
22 from .const
import CONNECTION_TIMEOUT, DOMAIN
24 _LOGGER = logging.getLogger(__name__)
26 REQUEST_REFRESH_COOLDOWN: Final = 5
30 """Store data about an APCUPSd and provide a few helper methods for easier accesses."""
33 def name(self) -> str | None:
34 """Return the name of the UPS, if available."""
35 return self.get(
"UPSNAME")
39 """Return the model of the UPS, if available."""
42 return self.get(
"APCMODEL")
or self.get(
"MODEL")
46 """Return the unique serial number of the UPS, if available."""
47 return self.get(
"SERIALNO")
51 """Store and coordinate the data retrieved from APCUPSd for all sensors.
53 For each entity to use, acts as the single point responsible for fetching
54 updates from the server.
57 config_entry: ConfigEntry
59 def __init__(self, hass: HomeAssistant, host: str, port: int) ->
None:
60 """Initialize the data object."""
65 update_interval=UPDATE_INTERVAL,
69 cooldown=REQUEST_REFRESH_COOLDOWN,
70 immediate=REQUEST_REFRESH_DEFAULT_IMMEDIATE,
78 """Return the DeviceInfo of this APC UPS, if serial number is available."""
80 identifiers={(DOMAIN, self.
datadata.serial_no
or self.
config_entryconfig_entry.entry_id)},
81 model=self.
datadata.model,
83 name=self.
datadata.name
or "APC UPS",
84 hw_version=self.
datadata.
get(
"FIRMWARE"),
85 sw_version=self.
datadata.
get(
"VERSION"),
89 """Fetch the latest status from APCUPSd.
91 Note that the result dict uses upper case for each resource, where our
92 integration uses lower cases as keys internally.
94 async
with asyncio.timeout(CONNECTION_TIMEOUT):
96 data = await aioapcaccess.request_status(self.
_host_host, self.
_port_port)
98 except (OSError, asyncio.IncompleteReadError)
as error:
None __init__(self, HomeAssistant hass, str host, int port)
DeviceInfo device_info(self)
APCUPSdData _async_update_data(self)
web.Response get(self, web.Request request, str config_key)