Add zwave_js sensor humidity device class (#47953)
This commit is contained in:
parent
059e9e8307
commit
40c12997ed
3 changed files with 22 additions and 6 deletions
|
@ -14,7 +14,12 @@ from homeassistant.components.sensor import (
|
|||
DOMAIN as SENSOR_DOMAIN,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||
from homeassistant.const import (
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
|
@ -83,10 +88,11 @@ class ZwaveSensorBase(ZWaveBaseEntity):
|
|||
if self.info.primary_value.metadata.unit == "kWh":
|
||||
return DEVICE_CLASS_ENERGY
|
||||
return DEVICE_CLASS_POWER
|
||||
if (
|
||||
isinstance(self.info.primary_value.property_, str)
|
||||
and "temperature" in self.info.primary_value.property_.lower()
|
||||
):
|
||||
if isinstance(self.info.primary_value.property_, str):
|
||||
property_lower = self.info.primary_value.property_.lower()
|
||||
if "humidity" in property_lower:
|
||||
return DEVICE_CLASS_HUMIDITY
|
||||
if "temperature" in property_lower:
|
||||
return DEVICE_CLASS_TEMPERATURE
|
||||
if self.info.primary_value.metadata.unit == "W":
|
||||
return DEVICE_CLASS_POWER
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
"""Provide common test tools for Z-Wave JS."""
|
||||
AIR_TEMPERATURE_SENSOR = "sensor.multisensor_6_air_temperature"
|
||||
HUMIDITY_SENSOR = "sensor.multisensor_6_humidity"
|
||||
ENERGY_SENSOR = "sensor.smart_plug_with_two_usb_ports_value_electric_consumed_2"
|
||||
POWER_SENSOR = "sensor.smart_plug_with_two_usb_ports_value_electric_consumed"
|
||||
SWITCH_ENTITY = "switch.smart_plug_with_two_usb_ports"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Test the Z-Wave JS sensor platform."""
|
||||
from homeassistant.const import (
|
||||
DEVICE_CLASS_ENERGY,
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_POWER,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
|
@ -12,6 +13,7 @@ from homeassistant.helpers import entity_registry as er
|
|||
from .common import (
|
||||
AIR_TEMPERATURE_SENSOR,
|
||||
ENERGY_SENSOR,
|
||||
HUMIDITY_SENSOR,
|
||||
NOTIFICATION_MOTION_SENSOR,
|
||||
POWER_SENSOR,
|
||||
)
|
||||
|
@ -26,6 +28,13 @@ async def test_numeric_sensor(hass, multisensor_6, integration):
|
|||
assert state.attributes["unit_of_measurement"] == TEMP_CELSIUS
|
||||
assert state.attributes["device_class"] == DEVICE_CLASS_TEMPERATURE
|
||||
|
||||
state = hass.states.get(HUMIDITY_SENSOR)
|
||||
|
||||
assert state
|
||||
assert state.state == "65.0"
|
||||
assert state.attributes["unit_of_measurement"] == "%"
|
||||
assert state.attributes["device_class"] == DEVICE_CLASS_HUMIDITY
|
||||
|
||||
|
||||
async def test_energy_sensors(hass, hank_binary_switch, integration):
|
||||
"""Test power and energy sensors."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue