Add setup type hints to supervisord (#63807)
Co-authored-by: epenet <epenet@users.noreply.github.com>pull/63834/head
parent
740a8c33ee
commit
896885a2c3
|
@ -1,4 +1,6 @@
|
|||
"""Sensor for Supervisord process status."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import xmlrpc.client
|
||||
|
||||
|
@ -6,7 +8,10 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||
from homeassistant.const import CONF_URL
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -20,15 +25,22 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||
)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
def setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the Supervisord platform."""
|
||||
url = config.get(CONF_URL)
|
||||
url = config[CONF_URL]
|
||||
try:
|
||||
supervisor_server = xmlrpc.client.ServerProxy(url)
|
||||
processes = supervisor_server.supervisor.getAllProcessInfo()
|
||||
# See this link to explain the type ignore:
|
||||
# http://supervisord.org/api.html#supervisor.rpcinterface.SupervisorNamespaceRPCInterface.getAllProcessInfo
|
||||
processes: list[dict] = supervisor_server.supervisor.getAllProcessInfo() # type: ignore[assignment]
|
||||
except ConnectionRefusedError:
|
||||
_LOGGER.error("Could not connect to Supervisord")
|
||||
return False
|
||||
return
|
||||
|
||||
add_entities(
|
||||
[SupervisorProcessSensor(info, supervisor_server) for info in processes], True
|
||||
|
|
Loading…
Reference in New Issue