1 """Sensor for Supervisord process status."""
3 from __future__
import annotations
8 import voluptuous
as vol
11 PLATFORM_SCHEMA
as SENSOR_PLATFORM_SCHEMA,
20 _LOGGER = logging.getLogger(__name__)
22 ATTR_DESCRIPTION =
"description"
25 DEFAULT_URL =
"http://localhost:9001/RPC2"
27 PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA.extend(
28 {vol.Optional(CONF_URL, default=DEFAULT_URL): cv.url}
35 add_entities: AddEntitiesCallback,
36 discovery_info: DiscoveryInfoType |
None =
None,
38 """Set up the Supervisord platform."""
39 url = config[CONF_URL]
41 supervisor_server = xmlrpc.client.ServerProxy(url)
44 processes: list[dict] = supervisor_server.supervisor.getAllProcessInfo()
45 except ConnectionRefusedError:
46 _LOGGER.error(
"Could not connect to Supervisord")
55 """Representation of a supervisor-monitored process."""
58 """Initialize the sensor."""
65 """Return the name of the sensor."""
70 """Return the state of the sensor."""
71 return self.
_info_info.
get(
"statename")
75 """Could the device be accessed during the last update call."""
80 """Return the state attributes."""
82 ATTR_DESCRIPTION: self.
_info_info.
get(
"description"),
83 ATTR_GROUP: self.
_info_info.
get(
"group"),
87 """Update device state."""
89 self.
_info_info = self.
_server_server.supervisor.getProcessInfo(
93 except ConnectionRefusedError:
94 _LOGGER.warning(
"Supervisord not available")
def __init__(self, info, server)
def extra_state_attributes(self)
web.Response get(self, web.Request request, str config_key)
def add_entities(account, async_add_entities, tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)