diff --git a/homeassistant/components/zwave_js/sensor.py b/homeassistant/components/zwave_js/sensor.py index a6d44cb62d0..d6cc9aabd49 100644 --- a/homeassistant/components/zwave_js/sensor.py +++ b/homeassistant/components/zwave_js/sensor.py @@ -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,11 +88,12 @@ 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() - ): - return DEVICE_CLASS_TEMPERATURE + 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 if self.info.primary_value.metadata.unit == "Lux": diff --git a/tests/components/zwave_js/common.py b/tests/components/zwave_js/common.py index f90a2e48ffa..0592f89902f 100644 --- a/tests/components/zwave_js/common.py +++ b/tests/components/zwave_js/common.py @@ -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" diff --git a/tests/components/zwave_js/test_sensor.py b/tests/components/zwave_js/test_sensor.py index 398d831e692..7b4cd8bcce6 100644 --- a/tests/components/zwave_js/test_sensor.py +++ b/tests/components/zwave_js/test_sensor.py @@ -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."""