mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
Add setup type hints to supervisord (#63807)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
740a8c33ee
commit
896885a2c3
@ -1,4 +1,6 @@
|
|||||||
"""Sensor for Supervisord process status."""
|
"""Sensor for Supervisord process status."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import xmlrpc.client
|
import xmlrpc.client
|
||||||
|
|
||||||
@ -6,7 +8,10 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||||
from homeassistant.const import CONF_URL
|
from homeassistant.const import CONF_URL
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
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__)
|
_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."""
|
"""Set up the Supervisord platform."""
|
||||||
url = config.get(CONF_URL)
|
url = config[CONF_URL]
|
||||||
try:
|
try:
|
||||||
supervisor_server = xmlrpc.client.ServerProxy(url)
|
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:
|
except ConnectionRefusedError:
|
||||||
_LOGGER.error("Could not connect to Supervisord")
|
_LOGGER.error("Could not connect to Supervisord")
|
||||||
return False
|
return
|
||||||
|
|
||||||
add_entities(
|
add_entities(
|
||||||
[SupervisorProcessSensor(info, supervisor_server) for info in processes], True
|
[SupervisorProcessSensor(info, supervisor_server) for info in processes], True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user