1 """Support for monitoring an OpenEVSE Charger."""
3 from __future__
import annotations
8 from requests
import RequestException
9 import voluptuous
as vol
12 PLATFORM_SCHEMA
as SENSOR_PLATFORM_SCHEMA,
15 SensorEntityDescription,
20 CONF_MONITORED_VARIABLES,
30 _LOGGER = logging.getLogger(__name__)
32 SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
35 name=
"Charging Status",
39 name=
"Charge Time Elapsed",
40 native_unit_of_measurement=UnitOfTime.MINUTES,
41 device_class=SensorDeviceClass.DURATION,
42 state_class=SensorStateClass.MEASUREMENT,
46 name=
"Ambient Temperature",
47 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
48 device_class=SensorDeviceClass.TEMPERATURE,
49 state_class=SensorStateClass.MEASUREMENT,
53 name=
"IR Temperature",
54 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
55 device_class=SensorDeviceClass.TEMPERATURE,
56 state_class=SensorStateClass.MEASUREMENT,
60 name=
"RTC Temperature",
61 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
62 device_class=SensorDeviceClass.TEMPERATURE,
63 state_class=SensorStateClass.MEASUREMENT,
67 name=
"Usage this Session",
68 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
69 device_class=SensorDeviceClass.ENERGY,
70 state_class=SensorStateClass.TOTAL_INCREASING,
75 native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
76 device_class=SensorDeviceClass.ENERGY,
77 state_class=SensorStateClass.TOTAL_INCREASING,
81 SENSOR_KEYS: list[str] = [desc.key
for desc
in SENSOR_TYPES]
83 PLATFORM_SCHEMA = SENSOR_PLATFORM_SCHEMA.extend(
85 vol.Required(CONF_HOST): cv.string,
86 vol.Optional(CONF_MONITORED_VARIABLES, default=[
"status"]): vol.All(
87 cv.ensure_list, [vol.In(SENSOR_KEYS)]
96 add_entities: AddEntitiesCallback,
97 discovery_info: DiscoveryInfoType |
None =
None,
99 """Set up the OpenEVSE sensor."""
100 host = config[CONF_HOST]
101 monitored_variables = config[CONF_MONITORED_VARIABLES]
103 charger = openevsewifi.Charger(host)
107 for description
in SENSOR_TYPES
108 if description.key
in monitored_variables
115 """Implementation of an OpenEVSE sensor."""
117 def __init__(self, charger, description: SensorEntityDescription) ->
None:
118 """Initialize the sensor."""
123 """Get the monitored data from the charger."""
126 if sensor_type ==
"status":
128 elif sensor_type ==
"charge_time":
130 elif sensor_type ==
"ambient_temp":
132 elif sensor_type ==
"ir_temp":
134 elif sensor_type ==
"rtc_temp":
136 elif sensor_type ==
"usage_session":
138 elif sensor_type ==
"usage_total":
142 except (RequestException, ValueError, KeyError):
143 _LOGGER.warning(
"Could not update status for %s", self.
namename)
None __init__(self, charger, SensorEntityDescription description)
str|UndefinedType|None name(self)
def add_entities(account, async_add_entities, tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)