Add humidifier support to promethease
parent
cf6480cda0
commit
d6751cea4f
|
@ -13,6 +13,11 @@ from homeassistant.components.climate.const import (
|
||||||
CURRENT_HVAC_ACTIONS,
|
CURRENT_HVAC_ACTIONS,
|
||||||
)
|
)
|
||||||
from homeassistant.components.http import HomeAssistantView
|
from homeassistant.components.http import HomeAssistantView
|
||||||
|
from homeassistant.components.humidifier.const import (
|
||||||
|
ATTR_AVAILABLE_MODES,
|
||||||
|
ATTR_HUMIDITY,
|
||||||
|
ATTR_MODE,
|
||||||
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_DEVICE_CLASS,
|
ATTR_DEVICE_CLASS,
|
||||||
ATTR_TEMPERATURE,
|
ATTR_TEMPERATURE,
|
||||||
|
@ -318,6 +323,32 @@ class PrometheusMetrics:
|
||||||
float(action == current_action)
|
float(action == current_action)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _handle_humidifier(self, state):
|
||||||
|
humidity = state.attributes.get(ATTR_HUMIDITY)
|
||||||
|
if humidity:
|
||||||
|
metric = self._metric(
|
||||||
|
"humidity", self.prometheus_cli.Gauge, "Target Relative Humidity"
|
||||||
|
)
|
||||||
|
metric.labels(**self._labels(state)).set(humidity)
|
||||||
|
|
||||||
|
metric = self._metric(
|
||||||
|
"humidifier_state",
|
||||||
|
self.prometheus_cli.Gauge,
|
||||||
|
"State of the humidifier (0/1)",
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
value = self.state_as_number(state)
|
||||||
|
except ValueError:
|
||||||
|
value = 0.0
|
||||||
|
metric.labels(**self._labels(state)).set(value)
|
||||||
|
|
||||||
|
mode = state.attributes.get(ATTR_MODE)
|
||||||
|
modes = state.attributes.get(ATTR_AVAILABLE_MODES)
|
||||||
|
if mode and modes:
|
||||||
|
metric = self._metric("mode", self.prometheus_cli.Gauge, "Humidifier Mode")
|
||||||
|
value = modes.index(mode)
|
||||||
|
metric.labels(**self._labels(state)).set(value)
|
||||||
|
|
||||||
def _handle_sensor(self, state):
|
def _handle_sensor(self, state):
|
||||||
unit = self._unit_string(state.attributes.get(ATTR_UNIT_OF_MEASUREMENT))
|
unit = self._unit_string(state.attributes.get(ATTR_UNIT_OF_MEASUREMENT))
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import setup
|
from homeassistant import setup
|
||||||
from homeassistant.components import climate, sensor
|
from homeassistant.components import climate, humidifier, sensor
|
||||||
from homeassistant.components.demo.sensor import DemoSensor
|
from homeassistant.components.demo.sensor import DemoSensor
|
||||||
import homeassistant.components.prometheus as prometheus
|
import homeassistant.components.prometheus as prometheus
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
@ -28,6 +28,10 @@ async def prometheus_client(loop, hass, hass_client):
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
await setup.async_setup_component(
|
||||||
|
hass, humidifier.DOMAIN, {"humidifier": [{"platform": "demo"}]}
|
||||||
|
)
|
||||||
|
|
||||||
sensor1 = DemoSensor(
|
sensor1 = DemoSensor(
|
||||||
None, "Television Energy", 74, None, ENERGY_KILO_WATT_HOUR, None
|
None, "Television Energy", 74, None, ENERGY_KILO_WATT_HOUR, None
|
||||||
)
|
)
|
||||||
|
@ -104,6 +108,24 @@ async def test_view(prometheus_client): # pylint: disable=redefined-outer-name
|
||||||
'friendly_name="HeatPump"} 25.0' in body
|
'friendly_name="HeatPump"} 25.0' in body
|
||||||
)
|
)
|
||||||
|
|
||||||
|
assert (
|
||||||
|
'humidity{domain="humidifier",'
|
||||||
|
'entity="humidifier.humidifier",'
|
||||||
|
'friendly_name="Humidifier"} 68.0' in body
|
||||||
|
)
|
||||||
|
|
||||||
|
assert (
|
||||||
|
'humidifier_state{domain="humidifier",'
|
||||||
|
'entity="humidifier.dehumidifier",'
|
||||||
|
'friendly_name="Dehumidifier"} 1.0' in body
|
||||||
|
)
|
||||||
|
|
||||||
|
assert (
|
||||||
|
'mode{domain="humidifier",'
|
||||||
|
'entity="humidifier.hygrostat",'
|
||||||
|
'friendly_name="Hygrostat"} 0.0' in body
|
||||||
|
)
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
'humidity_percent{domain="sensor",'
|
'humidity_percent{domain="sensor",'
|
||||||
'entity="sensor.outside_humidity",'
|
'entity="sensor.outside_humidity",'
|
||||||
|
|
Loading…
Reference in New Issue