1 """Support for information from HP iLO sensors."""
3 from __future__
import annotations
5 from datetime
import timedelta
9 import voluptuous
as vol
12 PLATFORM_SCHEMA
as SENSOR_PLATFORM_SCHEMA,
17 CONF_MONITORED_VARIABLES,
22 CONF_UNIT_OF_MEASUREMENT,
32 _LOGGER = logging.getLogger(__name__)
34 DEFAULT_NAME =
"HP ILO"
40 "server_name": [
"Server Name",
"get_server_name"],
41 "server_fqdn": [
"Server FQDN",
"get_server_fqdn"],
42 "server_host_data": [
"Server Host Data",
"get_host_data"],
43 "server_oa_info": [
"Server Onboard Administrator Info",
"get_oa_info"],
44 "server_power_status": [
"Server Power state",
"get_host_power_status"],
45 "server_power_readings": [
"Server Power readings",
"get_power_readings"],
46 "server_power_on_time": [
"Server Power On time",
"get_server_power_on_time"],
47 "server_asset_tag": [
"Server Asset Tag",
"get_asset_tag"],
48 "server_uid_status": [
"Server UID light",
"get_uid_status"],
49 "server_health": [
"Server Health",
"get_embedded_health"],
50 "network_settings": [
"Network Settings",
"get_network_settings"],
53 PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA.extend(
55 vol.Required(CONF_HOST): cv.string,
56 vol.Required(CONF_USERNAME): cv.string,
57 vol.Required(CONF_PASSWORD): cv.string,
58 vol.Optional(CONF_MONITORED_VARIABLES, default=[]): vol.All(
63 vol.Required(CONF_NAME): cv.string,
64 vol.Required(CONF_SENSOR_TYPE): vol.All(
65 cv.string, vol.In(SENSOR_TYPES)
67 vol.Optional(CONF_UNIT_OF_MEASUREMENT): cv.string,
68 vol.Optional(CONF_VALUE_TEMPLATE): cv.template,
73 vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
74 vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
82 add_entities: AddEntitiesCallback,
83 discovery_info: DiscoveryInfoType |
None =
None,
85 """Set up the HP iLO sensors."""
86 hostname = config[CONF_HOST]
87 port = config[CONF_PORT]
88 login = config[CONF_USERNAME]
89 password = config[CONF_PASSWORD]
90 monitored_variables = config[CONF_MONITORED_VARIABLES]
95 hp_ilo_data =
HpIloData(hostname, port, login, password)
96 except ValueError
as error:
102 for monitored_variable
in monitored_variables:
105 hp_ilo_data=hp_ilo_data,
106 sensor_name=f
"{config[CONF_NAME]} {monitored_variable[CONF_NAME]}",
107 sensor_type=monitored_variable[CONF_SENSOR_TYPE],
108 sensor_value_template=monitored_variable.get(CONF_VALUE_TEMPLATE),
109 unit_of_measurement=monitored_variable.get(CONF_UNIT_OF_MEASUREMENT),
111 devices.append(new_device)
117 """Representation of a HP iLO sensor."""
125 sensor_value_template,
128 """Initialize the HP iLO sensor."""
139 _LOGGER.debug(
"Created HP iLO sensor %r", self)
143 """Return the name of the sensor."""
144 return self.
_name_name
148 """Return the unit of measurement of the sensor."""
153 """Return the state of the sensor."""
158 """Return the device state attributes."""
162 """Get the latest data from HP iLO and updates the states."""
171 ilo_data=ilo_data, parse_result=
False
174 self.
_state_state = ilo_data
178 """Gets the latest data from HP iLO."""
181 """Initialize the data object."""
191 @Throttle(MIN_TIME_BETWEEN_UPDATES)
193 """Get the latest data from HP iLO."""
195 self.
datadata = hpilo.Ilo(
196 hostname=self.
_host_host,
199 port=self.
_port_port,
203 hpilo.IloCommunicationError,
204 hpilo.IloLoginFailed,
206 raise ValueError(f
"Unable to init HP ILO, {error}")
from error
def __init__(self, host, port, login, password)
def native_unit_of_measurement(self)
def extra_state_attributes(self)
def __init__(self, hass, hp_ilo_data, sensor_type, sensor_name, sensor_value_template, unit_of_measurement)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)
def add_entities(account, async_add_entities, tracked)