mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 14:57:09 +00:00
Add energy and power sensor tests & fix device_class (#45122)
This commit is contained in:
parent
eca6bc6a73
commit
3ebc5d45a8
@ -65,11 +65,9 @@ class ZwaveSensorBase(ZWaveBaseEntity):
|
|||||||
if self.info.primary_value.command_class == CommandClass.BATTERY:
|
if self.info.primary_value.command_class == CommandClass.BATTERY:
|
||||||
return DEVICE_CLASS_BATTERY
|
return DEVICE_CLASS_BATTERY
|
||||||
if self.info.primary_value.command_class == CommandClass.METER:
|
if self.info.primary_value.command_class == CommandClass.METER:
|
||||||
|
if self.info.primary_value.property_key_name == "kWh_Consumed":
|
||||||
|
return DEVICE_CLASS_ENERGY
|
||||||
return DEVICE_CLASS_POWER
|
return DEVICE_CLASS_POWER
|
||||||
if self.info.primary_value.property_key_name == "W_Consumed":
|
|
||||||
return DEVICE_CLASS_POWER
|
|
||||||
if self.info.primary_value.property_key_name == "kWh_Consumed":
|
|
||||||
return DEVICE_CLASS_ENERGY
|
|
||||||
if self.info.primary_value.property_ == "Air temperature":
|
if self.info.primary_value.property_ == "Air temperature":
|
||||||
return DEVICE_CLASS_TEMPERATURE
|
return DEVICE_CLASS_TEMPERATURE
|
||||||
return None
|
return None
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
"""Provide common test tools for Z-Wave JS."""
|
"""Provide common test tools for Z-Wave JS."""
|
||||||
AIR_TEMPERATURE_SENSOR = "sensor.multisensor_6_air_temperature"
|
AIR_TEMPERATURE_SENSOR = "sensor.multisensor_6_air_temperature"
|
||||||
|
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_current_value"
|
SWITCH_ENTITY = "switch.smart_plug_with_two_usb_ports_current_value"
|
||||||
|
@ -1,7 +1,14 @@
|
|||||||
"""Test the Z-Wave JS sensor platform."""
|
"""Test the Z-Wave JS sensor platform."""
|
||||||
from homeassistant.const import DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS
|
from homeassistant.const import (
|
||||||
|
DEVICE_CLASS_ENERGY,
|
||||||
|
DEVICE_CLASS_POWER,
|
||||||
|
DEVICE_CLASS_TEMPERATURE,
|
||||||
|
ENERGY_KILO_WATT_HOUR,
|
||||||
|
POWER_WATT,
|
||||||
|
TEMP_CELSIUS,
|
||||||
|
)
|
||||||
|
|
||||||
from .common import AIR_TEMPERATURE_SENSOR
|
from .common import AIR_TEMPERATURE_SENSOR, ENERGY_SENSOR, POWER_SENSOR
|
||||||
|
|
||||||
|
|
||||||
async def test_numeric_sensor(hass, multisensor_6, integration):
|
async def test_numeric_sensor(hass, multisensor_6, integration):
|
||||||
@ -12,3 +19,20 @@ async def test_numeric_sensor(hass, multisensor_6, integration):
|
|||||||
assert state.state == "9.0"
|
assert state.state == "9.0"
|
||||||
assert state.attributes["unit_of_measurement"] == TEMP_CELSIUS
|
assert state.attributes["unit_of_measurement"] == TEMP_CELSIUS
|
||||||
assert state.attributes["device_class"] == DEVICE_CLASS_TEMPERATURE
|
assert state.attributes["device_class"] == DEVICE_CLASS_TEMPERATURE
|
||||||
|
|
||||||
|
|
||||||
|
async def test_energy_sensors(hass, hank_binary_switch, integration):
|
||||||
|
"""Test power and energy sensors."""
|
||||||
|
state = hass.states.get(POWER_SENSOR)
|
||||||
|
|
||||||
|
assert state
|
||||||
|
assert state.state == "0.0"
|
||||||
|
assert state.attributes["unit_of_measurement"] == POWER_WATT
|
||||||
|
assert state.attributes["device_class"] == DEVICE_CLASS_POWER
|
||||||
|
|
||||||
|
state = hass.states.get(ENERGY_SENSOR)
|
||||||
|
|
||||||
|
assert state
|
||||||
|
assert state.state == "0.16"
|
||||||
|
assert state.attributes["unit_of_measurement"] == ENERGY_KILO_WATT_HOUR
|
||||||
|
assert state.attributes["device_class"] == DEVICE_CLASS_ENERGY
|
||||||
|
Loading…
x
Reference in New Issue
Block a user