mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Add support for the voltage sensor on the greeneye GEM (#30484)
* Add support for the voltage sensor on the greeneye GEM * Changed per suggestion @springstan
This commit is contained in:
parent
297c360d04
commit
ba3c3057da
@ -28,6 +28,7 @@ CONF_SENSORS = "sensors"
|
|||||||
CONF_SENSOR_TYPE = "sensor_type"
|
CONF_SENSOR_TYPE = "sensor_type"
|
||||||
CONF_TEMPERATURE_SENSORS = "temperature_sensors"
|
CONF_TEMPERATURE_SENSORS = "temperature_sensors"
|
||||||
CONF_TIME_UNIT = "time_unit"
|
CONF_TIME_UNIT = "time_unit"
|
||||||
|
CONF_VOLTAGE_SENSORS = "voltage"
|
||||||
|
|
||||||
DATA_GREENEYE_MONITOR = "greeneye_monitor"
|
DATA_GREENEYE_MONITOR = "greeneye_monitor"
|
||||||
DOMAIN = "greeneye_monitor"
|
DOMAIN = "greeneye_monitor"
|
||||||
@ -35,6 +36,7 @@ DOMAIN = "greeneye_monitor"
|
|||||||
SENSOR_TYPE_CURRENT = "current_sensor"
|
SENSOR_TYPE_CURRENT = "current_sensor"
|
||||||
SENSOR_TYPE_PULSE_COUNTER = "pulse_counter"
|
SENSOR_TYPE_PULSE_COUNTER = "pulse_counter"
|
||||||
SENSOR_TYPE_TEMPERATURE = "temperature_sensor"
|
SENSOR_TYPE_TEMPERATURE = "temperature_sensor"
|
||||||
|
SENSOR_TYPE_VOLTAGE = "voltage_sensor"
|
||||||
|
|
||||||
TEMPERATURE_UNIT_CELSIUS = "C"
|
TEMPERATURE_UNIT_CELSIUS = "C"
|
||||||
|
|
||||||
@ -55,6 +57,12 @@ TEMPERATURE_SENSORS_SCHEMA = vol.Schema(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
VOLTAGE_SENSOR_SCHEMA = vol.Schema(
|
||||||
|
{vol.Required(CONF_NUMBER): vol.Range(1, 48), vol.Required(CONF_NAME): cv.string}
|
||||||
|
)
|
||||||
|
|
||||||
|
VOLTAGE_SENSORS_SCHEMA = vol.All(cv.ensure_list, [VOLTAGE_SENSOR_SCHEMA])
|
||||||
|
|
||||||
PULSE_COUNTER_SCHEMA = vol.Schema(
|
PULSE_COUNTER_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required(CONF_NUMBER): vol.Range(1, 4),
|
vol.Required(CONF_NUMBER): vol.Range(1, 4),
|
||||||
@ -97,6 +105,7 @@ MONITOR_SCHEMA = vol.Schema(
|
|||||||
default={CONF_TEMPERATURE_UNIT: TEMPERATURE_UNIT_CELSIUS, CONF_SENSORS: []},
|
default={CONF_TEMPERATURE_UNIT: TEMPERATURE_UNIT_CELSIUS, CONF_SENSORS: []},
|
||||||
): TEMPERATURE_SENSORS_SCHEMA,
|
): TEMPERATURE_SENSORS_SCHEMA,
|
||||||
vol.Optional(CONF_PULSE_COUNTERS, default=[]): PULSE_COUNTERS_SCHEMA,
|
vol.Optional(CONF_PULSE_COUNTERS, default=[]): PULSE_COUNTERS_SCHEMA,
|
||||||
|
vol.Optional(CONF_VOLTAGE_SENSORS, default=[]): VOLTAGE_SENSORS_SCHEMA,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -140,6 +149,16 @@ async def async_setup(hass, config):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
voltage_configs = monitor_config[CONF_VOLTAGE_SENSORS]
|
||||||
|
for voltage_config in voltage_configs:
|
||||||
|
all_sensors.append(
|
||||||
|
{
|
||||||
|
CONF_SENSOR_TYPE: SENSOR_TYPE_VOLTAGE,
|
||||||
|
**monitor_serial_number,
|
||||||
|
**voltage_config,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
sensor_configs = monitor_config[CONF_TEMPERATURE_SENSORS]
|
sensor_configs = monitor_config[CONF_TEMPERATURE_SENSORS]
|
||||||
if sensor_configs:
|
if sensor_configs:
|
||||||
temperature_unit = {
|
temperature_unit = {
|
||||||
@ -168,7 +187,7 @@ async def async_setup(hass, config):
|
|||||||
if not all_sensors:
|
if not all_sensors:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"Configuration must specify at least one "
|
"Configuration must specify at least one "
|
||||||
"channel, pulse counter or temperature sensor"
|
"channel, voltage, pulse counter or temperature sensor"
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ from . import (
|
|||||||
SENSOR_TYPE_CURRENT,
|
SENSOR_TYPE_CURRENT,
|
||||||
SENSOR_TYPE_PULSE_COUNTER,
|
SENSOR_TYPE_PULSE_COUNTER,
|
||||||
SENSOR_TYPE_TEMPERATURE,
|
SENSOR_TYPE_TEMPERATURE,
|
||||||
|
SENSOR_TYPE_VOLTAGE,
|
||||||
TIME_UNIT_HOUR,
|
TIME_UNIT_HOUR,
|
||||||
TIME_UNIT_MINUTE,
|
TIME_UNIT_MINUTE,
|
||||||
TIME_UNIT_SECOND,
|
TIME_UNIT_SECOND,
|
||||||
@ -31,6 +32,7 @@ UNIT_WATTS = POWER_WATT
|
|||||||
COUNTER_ICON = "mdi:counter"
|
COUNTER_ICON = "mdi:counter"
|
||||||
CURRENT_SENSOR_ICON = "mdi:flash"
|
CURRENT_SENSOR_ICON = "mdi:flash"
|
||||||
TEMPERATURE_ICON = "mdi:thermometer"
|
TEMPERATURE_ICON = "mdi:thermometer"
|
||||||
|
VOLTAGE_ICON = "mdi:current-ac"
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||||
@ -70,6 +72,14 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||||||
sensor[CONF_TEMPERATURE_UNIT],
|
sensor[CONF_TEMPERATURE_UNIT],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
elif sensor_type == SENSOR_TYPE_VOLTAGE:
|
||||||
|
entities.append(
|
||||||
|
VoltageSensor(
|
||||||
|
sensor[CONF_MONITOR_SERIAL_NUMBER],
|
||||||
|
sensor[CONF_NUMBER],
|
||||||
|
sensor[CONF_NAME],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
@ -276,3 +286,35 @@ class TemperatureSensor(GEMSensor):
|
|||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Return the unit of measurement for this sensor (user specified)."""
|
"""Return the unit of measurement for this sensor (user specified)."""
|
||||||
return self._unit
|
return self._unit
|
||||||
|
|
||||||
|
|
||||||
|
class VoltageSensor(GEMSensor):
|
||||||
|
"""Entity showing voltage."""
|
||||||
|
|
||||||
|
def __init__(self, monitor_serial_number, number, name):
|
||||||
|
"""Construct the entity."""
|
||||||
|
super().__init__(monitor_serial_number, name, "volts", number)
|
||||||
|
self._monitor = None
|
||||||
|
|
||||||
|
def _get_sensor(self, monitor):
|
||||||
|
"""Wire the updates to a current channel."""
|
||||||
|
self._monitor = monitor
|
||||||
|
return monitor.channels[self._number - 1]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def icon(self):
|
||||||
|
"""Return the icon that should represent this sensor in the UI."""
|
||||||
|
return VOLTAGE_ICON
|
||||||
|
|
||||||
|
@property
|
||||||
|
def state(self):
|
||||||
|
"""Return the current voltage being reported by this sensor."""
|
||||||
|
if not self._monitor.voltage:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return self._monitor.voltage
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unit_of_measurement(self):
|
||||||
|
"""Return the unit of measurement for this sensor."""
|
||||||
|
return "V"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user