Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion homeassistant/components/greeneye_monitor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@
CONF_SENSOR_TYPE = "sensor_type"
CONF_TEMPERATURE_SENSORS = "temperature_sensors"
CONF_TIME_UNIT = "time_unit"
CONF_VOLTAGE_SENSORS = "voltage"

DATA_GREENEYE_MONITOR = "greeneye_monitor"
DOMAIN = "greeneye_monitor"

SENSOR_TYPE_CURRENT = "current_sensor"
SENSOR_TYPE_PULSE_COUNTER = "pulse_counter"
SENSOR_TYPE_TEMPERATURE = "temperature_sensor"
SENSOR_TYPE_VOLTAGE = "voltage_sensor"

TEMPERATURE_UNIT_CELSIUS = "C"

Expand All @@ -55,6 +57,12 @@
}
)

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(
{
vol.Required(CONF_NUMBER): vol.Range(1, 4),
Expand Down Expand Up @@ -97,6 +105,7 @@
default={CONF_TEMPERATURE_UNIT: TEMPERATURE_UNIT_CELSIUS, CONF_SENSORS: []},
): TEMPERATURE_SENSORS_SCHEMA,
vol.Optional(CONF_PULSE_COUNTERS, default=[]): PULSE_COUNTERS_SCHEMA,
vol.Optional(CONF_VOLTAGE_SENSORS, default=[]): VOLTAGE_SENSORS_SCHEMA,
}
)

Expand Down Expand Up @@ -140,6 +149,16 @@ async def close_server(*args):
}
)

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]
if sensor_configs:
temperature_unit = {
Expand Down Expand Up @@ -168,7 +187,7 @@ async def close_server(*args):
if not all_sensors:
_LOGGER.error(
"Configuration must specify at least one "
"channel, pulse counter or temperature sensor"
"channel, voltage, pulse counter or temperature sensor"
)
return False

Expand Down
42 changes: 42 additions & 0 deletions homeassistant/components/greeneye_monitor/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
SENSOR_TYPE_CURRENT,
SENSOR_TYPE_PULSE_COUNTER,
SENSOR_TYPE_TEMPERATURE,
SENSOR_TYPE_VOLTAGE,
TIME_UNIT_HOUR,
TIME_UNIT_MINUTE,
TIME_UNIT_SECOND,
Expand All @@ -31,6 +32,7 @@
COUNTER_ICON = "mdi:counter"
CURRENT_SENSOR_ICON = "mdi:flash"
TEMPERATURE_ICON = "mdi:thermometer"
VOLTAGE_ICON = "mdi:current-ac"


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
Expand Down Expand Up @@ -70,6 +72,14 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
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)

Expand Down Expand Up @@ -276,3 +286,35 @@ def state(self):
def unit_of_measurement(self):
"""Return the unit of measurement for this sensor (user specified)."""
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"