Move temperature conversions to sensor base class (8/8) (#54483)

* Move temperature conversions to entity base class (8/8)

* Fix wallbox sensor

* Fix tests
This commit is contained in:
Erik Montnemery 2021-08-11 21:17:16 +02:00 committed by GitHub
parent e23750b2a4
commit ae507aeed1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 141 additions and 129 deletions

View file

@ -141,7 +141,7 @@ class ValloxSensor(SensorEntity):
return self._name return self._name
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement.""" """Return the unit of measurement."""
return self._unit_of_measurement return self._unit_of_measurement
@ -161,7 +161,7 @@ class ValloxSensor(SensorEntity):
return self._available return self._available
@property @property
def state(self): def native_value(self):
"""Return the state.""" """Return the state."""
return self._state return self._state

View file

@ -110,7 +110,7 @@ class VasttrafikDepartureSensor(SensorEntity):
return self._attributes return self._attributes
@property @property
def state(self): def native_value(self):
"""Return the next departure time.""" """Return the next departure time."""
return self._state return self._state

View file

@ -45,14 +45,14 @@ class VelbusSensor(VelbusEntity, SensorEntity):
return self._module.get_class(self._channel) return self._module.get_class(self._channel)
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
if self._is_counter: if self._is_counter:
return self._module.get_counter_state(self._channel) return self._module.get_counter_state(self._channel)
return self._module.get_state(self._channel) return self._module.get_state(self._channel)
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit this state is expressed in.""" """Return the unit this state is expressed in."""
if self._is_counter: if self._is_counter:
return self._module.get_counter_unit(self._channel) return self._module.get_counter_unit(self._channel)

View file

@ -53,12 +53,12 @@ class VeraSensor(VeraDevice[veraApi.VeraSensor], SensorEntity):
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id) self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
@property @property
def state(self) -> str: def native_value(self) -> str:
"""Return the name of the sensor.""" """Return the name of the sensor."""
return self.current_value return self.current_value
@property @property
def unit_of_measurement(self) -> str | None: def native_unit_of_measurement(self) -> str | None:
"""Return the unit of measurement of this entity, if any.""" """Return the unit of measurement of this entity, if any."""
if self.vera_device.category == veraApi.CATEGORY_TEMPERATURE_SENSOR: if self.vera_device.category == veraApi.CATEGORY_TEMPERATURE_SENSOR:

View file

@ -51,7 +51,7 @@ class VerisureThermometer(CoordinatorEntity, SensorEntity):
coordinator: VerisureDataUpdateCoordinator coordinator: VerisureDataUpdateCoordinator
_attr_device_class = DEVICE_CLASS_TEMPERATURE _attr_device_class = DEVICE_CLASS_TEMPERATURE
_attr_unit_of_measurement = TEMP_CELSIUS _attr_native_unit_of_measurement = TEMP_CELSIUS
def __init__( def __init__(
self, coordinator: VerisureDataUpdateCoordinator, serial_number: str self, coordinator: VerisureDataUpdateCoordinator, serial_number: str
@ -84,7 +84,7 @@ class VerisureThermometer(CoordinatorEntity, SensorEntity):
} }
@property @property
def state(self) -> str | None: def native_value(self) -> str | None:
"""Return the state of the entity.""" """Return the state of the entity."""
return self.coordinator.data["climate"][self.serial_number]["temperature"] return self.coordinator.data["climate"][self.serial_number]["temperature"]
@ -104,7 +104,7 @@ class VerisureHygrometer(CoordinatorEntity, SensorEntity):
coordinator: VerisureDataUpdateCoordinator coordinator: VerisureDataUpdateCoordinator
_attr_device_class = DEVICE_CLASS_HUMIDITY _attr_device_class = DEVICE_CLASS_HUMIDITY
_attr_unit_of_measurement = PERCENTAGE _attr_native_unit_of_measurement = PERCENTAGE
def __init__( def __init__(
self, coordinator: VerisureDataUpdateCoordinator, serial_number: str self, coordinator: VerisureDataUpdateCoordinator, serial_number: str
@ -137,7 +137,7 @@ class VerisureHygrometer(CoordinatorEntity, SensorEntity):
} }
@property @property
def state(self) -> str | None: def native_value(self) -> str | None:
"""Return the state of the entity.""" """Return the state of the entity."""
return self.coordinator.data["climate"][self.serial_number]["humidity"] return self.coordinator.data["climate"][self.serial_number]["humidity"]
@ -156,7 +156,7 @@ class VerisureMouseDetection(CoordinatorEntity, SensorEntity):
coordinator: VerisureDataUpdateCoordinator coordinator: VerisureDataUpdateCoordinator
_attr_unit_of_measurement = "Mice" _attr_native_unit_of_measurement = "Mice"
def __init__( def __init__(
self, coordinator: VerisureDataUpdateCoordinator, serial_number: str self, coordinator: VerisureDataUpdateCoordinator, serial_number: str
@ -186,7 +186,7 @@ class VerisureMouseDetection(CoordinatorEntity, SensorEntity):
} }
@property @property
def state(self) -> str | None: def native_value(self) -> str | None:
"""Return the state of the entity.""" """Return the state of the entity."""
return self.coordinator.data["mice"][self.serial_number]["detections"] return self.coordinator.data["mice"][self.serial_number]["detections"]

View file

@ -65,12 +65,12 @@ class VSensor(SensorEntity):
return self._name return self._name
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement.""" """Return the unit of measurement."""
return self._unit return self._unit

View file

@ -151,5 +151,5 @@ class VersionSensor(SensorEntity):
async def async_update(self): async def async_update(self):
"""Get the latest version information.""" """Get the latest version information."""
await self.data.async_update() await self.data.async_update()
self._attr_state = self.data.api.version self._attr_native_value = self.data.api.version
self._attr_extra_state_attributes = self.data.api.version_data self._attr_extra_state_attributes = self.data.api.version_data

View file

@ -103,7 +103,7 @@ class ViaggiaTrenoSensor(SensorEntity):
return self._name return self._name
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state
@ -113,7 +113,7 @@ class ViaggiaTrenoSensor(SensorEntity):
return self._icon return self._icon
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement.""" """Return the unit of measurement."""
return self._unit return self._unit

View file

@ -369,12 +369,12 @@ class ViCareSensor(SensorEntity):
return self._sensor[CONF_ICON] return self._sensor[CONF_ICON]
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement.""" """Return the unit of measurement."""
return self._sensor[CONF_UNIT_OF_MEASUREMENT] return self._sensor[CONF_UNIT_OF_MEASUREMENT]

View file

@ -72,7 +72,7 @@ class VilfoRouterSensor(SensorEntity):
return f"{parent_device_name} {sensor_name}" return f"{parent_device_name} {sensor_name}"
@property @property
def state(self): def native_value(self):
"""Return the state.""" """Return the state."""
return self._state return self._state
@ -82,7 +82,7 @@ class VilfoRouterSensor(SensorEntity):
return self._unique_id return self._unique_id
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement of this entity.""" """Return the unit of measurement of this entity."""
return SENSOR_TYPES[self.sensor_type].get(ATTR_UNIT) return SENSOR_TYPES[self.sensor_type].get(ATTR_UNIT)

View file

@ -97,7 +97,7 @@ class VolkszaehlerSensor(SensorEntity):
return SENSOR_TYPES[self.type][2] return SENSOR_TYPES[self.type][2]
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit the value is expressed in.""" """Return the unit the value is expressed in."""
return SENSOR_TYPES[self.type][1] return SENSOR_TYPES[self.type][1]
@ -107,7 +107,7 @@ class VolkszaehlerSensor(SensorEntity):
return self.vz_api.available return self.vz_api.available
@property @property
def state(self): def native_value(self):
"""Return the state of the resources.""" """Return the state of the resources."""
return self._state return self._state

View file

@ -15,11 +15,11 @@ class VolvoSensor(VolvoEntity, SensorEntity):
"""Representation of a Volvo sensor.""" """Representation of a Volvo sensor."""
@property @property
def state(self): def native_value(self):
"""Return the state.""" """Return the state."""
return self.instrument.state return self.instrument.state
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement.""" """Return the unit of measurement."""
return self.instrument.unit return self.instrument.unit

View file

@ -92,12 +92,12 @@ class VultrSensor(SensorEntity):
return self._icon return self._icon
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement to present the value in.""" """Return the unit of measurement to present the value in."""
return self._units return self._units
@property @property
def state(self): def native_value(self):
"""Return the value of this given sensor type.""" """Return the value of this given sensor type."""
try: try:
return round(float(self.data.get(self._condition)), 2) return round(float(self.data.get(self._condition)), 2)

View file

@ -1,6 +1,6 @@
"""Home Assistant component for accessing the Wallbox Portal API. The sensor component creates multiple sensors regarding wallbox performance.""" """Home Assistant component for accessing the Wallbox Portal API. The sensor component creates multiple sensors regarding wallbox performance."""
from homeassistant.helpers.entity import Entity from homeassistant.components.sensor import SensorEntity
from homeassistant.helpers.update_coordinator import CoordinatorEntity from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import ( from .const import (
@ -28,7 +28,7 @@ async def async_setup_entry(hass, config, async_add_entities):
) )
class WallboxSensor(CoordinatorEntity, Entity): class WallboxSensor(CoordinatorEntity, SensorEntity):
"""Representation of the Wallbox portal.""" """Representation of the Wallbox portal."""
def __init__(self, coordinator, idx, ent, config): def __init__(self, coordinator, idx, ent, config):
@ -46,12 +46,12 @@ class WallboxSensor(CoordinatorEntity, Entity):
return self._name return self._name
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self.coordinator.data[self._ent] return self.coordinator.data[self._ent]
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of the sensor.""" """Return the unit of the sensor."""
return self._unit return self._unit

View file

@ -129,7 +129,7 @@ class WaqiSensor(SensorEntity):
return "mdi:cloud" return "mdi:cloud"
@property @property
def state(self): def native_value(self):
"""Return the state of the device.""" """Return the state of the device."""
if self._data is not None: if self._data is not None:
return self._data.get("aqi") return self._data.get("aqi")
@ -146,7 +146,7 @@ class WaqiSensor(SensorEntity):
return self.uid return self.uid
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any.""" """Return the unit of measurement of this entity, if any."""
return "AQI" return "AQI"

View file

@ -101,7 +101,7 @@ class WaterFurnaceSensor(SensorEntity):
return self._name return self._name
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state
@ -111,7 +111,7 @@ class WaterFurnaceSensor(SensorEntity):
return self._icon return self._icon
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the units of measurement.""" """Return the units of measurement."""
return self._unit_of_measurement return self._unit_of_measurement

View file

@ -202,7 +202,7 @@ class WazeTravelTime(SensorEntity):
return self._name return self._name
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
if self._waze_data.duration is not None: if self._waze_data.duration is not None:
return round(self._waze_data.duration) return round(self._waze_data.duration)
@ -210,7 +210,7 @@ class WazeTravelTime(SensorEntity):
return None return None
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement.""" """Return the unit of measurement."""
return TIME_MINUTES return TIME_MINUTES

View file

@ -53,12 +53,12 @@ class APICount(SensorEntity):
return "Connected clients" return "Connected clients"
@property @property
def state(self) -> int: def native_value(self) -> int:
"""Return current API count.""" """Return current API count."""
return self.count return self.count
@property @property
def unit_of_measurement(self) -> str: def native_unit_of_measurement(self) -> str:
"""Return the unit of measurement.""" """Return the unit of measurement."""
return "clients" return "clients"

View file

@ -70,12 +70,12 @@ class WhoisSensor(SensorEntity):
return "mdi:calendar-clock" return "mdi:calendar-clock"
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement to present the value in.""" """Return the unit of measurement to present the value in."""
return TIME_DAYS return TIME_DAYS
@property @property
def state(self): def native_value(self):
"""Return the expiration days for hostname.""" """Return the expiration days for hostname."""
return self._state return self._state

View file

@ -78,12 +78,12 @@ class NumberEntity(WiffiEntity, SensorEntity):
return self._device_class return self._device_class
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement of this entity.""" """Return the unit of measurement of this entity."""
return self._unit_of_measurement return self._unit_of_measurement
@property @property
def state(self): def native_value(self):
"""Return the value of the entity.""" """Return the value of the entity."""
return self._value return self._value
@ -111,7 +111,7 @@ class StringEntity(WiffiEntity, SensorEntity):
self.reset_expiration_date() self.reset_expiration_date()
@property @property
def state(self): def native_value(self):
"""Return the value of the entity.""" """Return the value of the entity."""
return self._value return self._value

View file

@ -62,7 +62,7 @@ class WinkSensorEntity(WinkDevice, SensorEntity):
self.hass.data[DOMAIN]["entities"]["sensor"].append(self) self.hass.data[DOMAIN]["entities"]["sensor"].append(self)
@property @property
def state(self): def native_value(self):
"""Return the state.""" """Return the state."""
state = None state = None
if self.capability == "humidity": if self.capability == "humidity":
@ -82,7 +82,7 @@ class WinkSensorEntity(WinkDevice, SensorEntity):
return state return state
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any.""" """Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement return self._unit_of_measurement

View file

@ -83,7 +83,7 @@ class WirelessTagSensor(WirelessTagBaseSensor, SensorEntity):
return self.name.lower().replace(" ", "_") return self.name.lower().replace(" ", "_")
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state
@ -93,7 +93,7 @@ class WirelessTagSensor(WirelessTagBaseSensor, SensorEntity):
return self._sensor_type return self._sensor_type
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement.""" """Return the unit of measurement."""
return self._sensor.unit return self._sensor.unit

View file

@ -30,11 +30,11 @@ class WithingsHealthSensor(BaseWithingsSensor, SensorEntity):
"""Implementation of a Withings sensor.""" """Implementation of a Withings sensor."""
@property @property
def state(self) -> None | str | int | float: def native_value(self) -> None | str | int | float:
"""Return the state of the entity.""" """Return the state of the entity."""
return self._state_data return self._state_data
@property @property
def unit_of_measurement(self) -> str: def native_unit_of_measurement(self) -> str:
"""Return the unit of measurement of this entity, if any.""" """Return the unit of measurement of this entity, if any."""
return self._attribute.unit_of_measurement return self._attribute.unit_of_measurement

View file

@ -48,7 +48,7 @@ class WLEDEstimatedCurrentSensor(WLEDEntity, SensorEntity):
"""Defines a WLED estimated current sensor.""" """Defines a WLED estimated current sensor."""
_attr_icon = "mdi:power" _attr_icon = "mdi:power"
_attr_unit_of_measurement = ELECTRIC_CURRENT_MILLIAMPERE _attr_native_unit_of_measurement = ELECTRIC_CURRENT_MILLIAMPERE
_attr_device_class = DEVICE_CLASS_CURRENT _attr_device_class = DEVICE_CLASS_CURRENT
def __init__(self, coordinator: WLEDDataUpdateCoordinator) -> None: def __init__(self, coordinator: WLEDDataUpdateCoordinator) -> None:
@ -66,7 +66,7 @@ class WLEDEstimatedCurrentSensor(WLEDEntity, SensorEntity):
} }
@property @property
def state(self) -> int: def native_value(self) -> int:
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self.coordinator.data.info.leds.power return self.coordinator.data.info.leds.power
@ -84,7 +84,7 @@ class WLEDUptimeSensor(WLEDEntity, SensorEntity):
self._attr_unique_id = f"{coordinator.data.info.mac_address}_uptime" self._attr_unique_id = f"{coordinator.data.info.mac_address}_uptime"
@property @property
def state(self) -> str: def native_value(self) -> str:
"""Return the state of the sensor.""" """Return the state of the sensor."""
uptime = utcnow() - timedelta(seconds=self.coordinator.data.info.uptime) uptime = utcnow() - timedelta(seconds=self.coordinator.data.info.uptime)
return uptime.replace(microsecond=0).isoformat() return uptime.replace(microsecond=0).isoformat()
@ -95,7 +95,7 @@ class WLEDFreeHeapSensor(WLEDEntity, SensorEntity):
_attr_icon = "mdi:memory" _attr_icon = "mdi:memory"
_attr_entity_registry_enabled_default = False _attr_entity_registry_enabled_default = False
_attr_unit_of_measurement = DATA_BYTES _attr_native_unit_of_measurement = DATA_BYTES
def __init__(self, coordinator: WLEDDataUpdateCoordinator) -> None: def __init__(self, coordinator: WLEDDataUpdateCoordinator) -> None:
"""Initialize WLED free heap sensor.""" """Initialize WLED free heap sensor."""
@ -104,7 +104,7 @@ class WLEDFreeHeapSensor(WLEDEntity, SensorEntity):
self._attr_unique_id = f"{coordinator.data.info.mac_address}_free_heap" self._attr_unique_id = f"{coordinator.data.info.mac_address}_free_heap"
@property @property
def state(self) -> int: def native_value(self) -> int:
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self.coordinator.data.info.free_heap return self.coordinator.data.info.free_heap
@ -113,7 +113,7 @@ class WLEDWifiSignalSensor(WLEDEntity, SensorEntity):
"""Defines a WLED Wi-Fi signal sensor.""" """Defines a WLED Wi-Fi signal sensor."""
_attr_icon = "mdi:wifi" _attr_icon = "mdi:wifi"
_attr_unit_of_measurement = PERCENTAGE _attr_native_unit_of_measurement = PERCENTAGE
_attr_entity_registry_enabled_default = False _attr_entity_registry_enabled_default = False
def __init__(self, coordinator: WLEDDataUpdateCoordinator) -> None: def __init__(self, coordinator: WLEDDataUpdateCoordinator) -> None:
@ -123,7 +123,7 @@ class WLEDWifiSignalSensor(WLEDEntity, SensorEntity):
self._attr_unique_id = f"{coordinator.data.info.mac_address}_wifi_signal" self._attr_unique_id = f"{coordinator.data.info.mac_address}_wifi_signal"
@property @property
def state(self) -> int | None: def native_value(self) -> int | None:
"""Return the state of the sensor.""" """Return the state of the sensor."""
if not self.coordinator.data.info.wifi: if not self.coordinator.data.info.wifi:
return None return None
@ -134,7 +134,7 @@ class WLEDWifiRSSISensor(WLEDEntity, SensorEntity):
"""Defines a WLED Wi-Fi RSSI sensor.""" """Defines a WLED Wi-Fi RSSI sensor."""
_attr_device_class = DEVICE_CLASS_SIGNAL_STRENGTH _attr_device_class = DEVICE_CLASS_SIGNAL_STRENGTH
_attr_unit_of_measurement = SIGNAL_STRENGTH_DECIBELS_MILLIWATT _attr_native_unit_of_measurement = SIGNAL_STRENGTH_DECIBELS_MILLIWATT
_attr_entity_registry_enabled_default = False _attr_entity_registry_enabled_default = False
def __init__(self, coordinator: WLEDDataUpdateCoordinator) -> None: def __init__(self, coordinator: WLEDDataUpdateCoordinator) -> None:
@ -144,7 +144,7 @@ class WLEDWifiRSSISensor(WLEDEntity, SensorEntity):
self._attr_unique_id = f"{coordinator.data.info.mac_address}_wifi_rssi" self._attr_unique_id = f"{coordinator.data.info.mac_address}_wifi_rssi"
@property @property
def state(self) -> int | None: def native_value(self) -> int | None:
"""Return the state of the sensor.""" """Return the state of the sensor."""
if not self.coordinator.data.info.wifi: if not self.coordinator.data.info.wifi:
return None return None
@ -164,7 +164,7 @@ class WLEDWifiChannelSensor(WLEDEntity, SensorEntity):
self._attr_unique_id = f"{coordinator.data.info.mac_address}_wifi_channel" self._attr_unique_id = f"{coordinator.data.info.mac_address}_wifi_channel"
@property @property
def state(self) -> int | None: def native_value(self) -> int | None:
"""Return the state of the sensor.""" """Return the state of the sensor."""
if not self.coordinator.data.info.wifi: if not self.coordinator.data.info.wifi:
return None return None
@ -184,7 +184,7 @@ class WLEDWifiBSSIDSensor(WLEDEntity, SensorEntity):
self._attr_unique_id = f"{coordinator.data.info.mac_address}_wifi_bssid" self._attr_unique_id = f"{coordinator.data.info.mac_address}_wifi_bssid"
@property @property
def state(self) -> str | None: def native_value(self) -> str | None:
"""Return the state of the sensor.""" """Return the state of the sensor."""
if not self.coordinator.data.info.wifi: if not self.coordinator.data.info.wifi:
return None return None

View file

@ -63,7 +63,7 @@ class WolfLinkSensor(CoordinatorEntity, SensorEntity):
return f"{self.wolf_object.name}" return f"{self.wolf_object.name}"
@property @property
def state(self): def native_value(self):
"""Return the state. Wolf Client is returning only changed values so we need to store old value here.""" """Return the state. Wolf Client is returning only changed values so we need to store old value here."""
if self.wolf_object.parameter_id in self.coordinator.data: if self.wolf_object.parameter_id in self.coordinator.data:
new_state = self.coordinator.data[self.wolf_object.parameter_id] new_state = self.coordinator.data[self.wolf_object.parameter_id]
@ -95,7 +95,7 @@ class WolfLinkHours(WolfLinkSensor):
return "mdi:clock" return "mdi:clock"
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit the value is expressed in.""" """Return the unit the value is expressed in."""
return TIME_HOURS return TIME_HOURS
@ -109,7 +109,7 @@ class WolfLinkTemperature(WolfLinkSensor):
return DEVICE_CLASS_TEMPERATURE return DEVICE_CLASS_TEMPERATURE
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit the value is expressed in.""" """Return the unit the value is expressed in."""
return TEMP_CELSIUS return TEMP_CELSIUS
@ -123,7 +123,7 @@ class WolfLinkPressure(WolfLinkSensor):
return DEVICE_CLASS_PRESSURE return DEVICE_CLASS_PRESSURE
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit the value is expressed in.""" """Return the unit the value is expressed in."""
return PRESSURE_BAR return PRESSURE_BAR
@ -132,7 +132,7 @@ class WolfLinkPercentage(WolfLinkSensor):
"""Class for percentage based entities.""" """Class for percentage based entities."""
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit the value is expressed in.""" """Return the unit the value is expressed in."""
return self.wolf_object.unit return self.wolf_object.unit
@ -146,7 +146,7 @@ class WolfLinkState(WolfLinkSensor):
return "wolflink__state" return "wolflink__state"
@property @property
def state(self): def native_value(self):
"""Return the state converting with supported values.""" """Return the state converting with supported values."""
state = super().state state = super().state
resolved_state = [ resolved_state = [

View file

@ -54,7 +54,7 @@ class WorldClockSensor(SensorEntity):
return self._name return self._name
@property @property
def state(self): def native_value(self):
"""Return the state of the device.""" """Return the state of the device."""
return self._state return self._state

View file

@ -88,7 +88,7 @@ class WorldTidesInfoSensor(SensorEntity):
return attr return attr
@property @property
def state(self): def native_value(self):
"""Return the state of the device.""" """Return the state of the device."""
if self.data: if self.data:
if "High" in str(self.data["extremes"][0]["type"]): if "High" in str(self.data["extremes"][0]["type"]):

View file

@ -68,12 +68,12 @@ class WorxLandroidSensor(SensorEntity):
return f"worxlandroid-{self.sensor}" return f"worxlandroid-{self.sensor}"
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement of the sensor.""" """Return the unit of measurement of the sensor."""
if self.sensor == "battery": if self.sensor == "battery":
return PERCENTAGE return PERCENTAGE

View file

@ -88,7 +88,7 @@ class WashingtonStateTransportSensor(SensorEntity):
return self._name return self._name
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state
@ -96,7 +96,7 @@ class WashingtonStateTransportSensor(SensorEntity):
class WashingtonStateTravelTimeSensor(WashingtonStateTransportSensor): class WashingtonStateTravelTimeSensor(WashingtonStateTransportSensor):
"""Travel time sensor from WSDOT.""" """Travel time sensor from WSDOT."""
_attr_unit_of_measurement = TIME_MINUTES _attr_native_unit_of_measurement = TIME_MINUTES
def __init__(self, name, access_code, travel_time_id): def __init__(self, name, access_code, travel_time_id):
"""Construct a travel time sensor.""" """Construct a travel time sensor."""

View file

@ -369,7 +369,7 @@ class XBeeDigitalOut(XBeeDigitalIn):
class XBeeAnalogIn(SensorEntity): class XBeeAnalogIn(SensorEntity):
"""Representation of a GPIO pin configured as an analog input.""" """Representation of a GPIO pin configured as an analog input."""
_attr_unit_of_measurement = PERCENTAGE _attr_native_unit_of_measurement = PERCENTAGE
def __init__(self, config, device): def __init__(self, config, device):
"""Initialize the XBee analog in device.""" """Initialize the XBee analog in device."""
@ -416,7 +416,7 @@ class XBeeAnalogIn(SensorEntity):
return self._config.should_poll return self._config.should_poll
@property @property
def state(self): def sensor_state(self):
"""Return the state of the entity.""" """Return the state of the entity."""
return self._value return self._value

View file

@ -47,7 +47,7 @@ class XBeeTemperatureSensor(SensorEntity):
"""Representation of XBee Pro temperature sensor.""" """Representation of XBee Pro temperature sensor."""
_attr_device_class = DEVICE_CLASS_TEMPERATURE _attr_device_class = DEVICE_CLASS_TEMPERATURE
_attr_unit_of_measurement = TEMP_CELSIUS _attr_native_unit_of_measurement = TEMP_CELSIUS
def __init__(self, config, device): def __init__(self, config, device):
"""Initialize the sensor.""" """Initialize the sensor."""
@ -61,7 +61,7 @@ class XBeeTemperatureSensor(SensorEntity):
return self._config.name return self._config.name
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._temp return self._temp

View file

@ -33,7 +33,7 @@ class XboxSensorEntity(XboxBaseSensorEntity, SensorEntity):
"""Representation of a Xbox presence state.""" """Representation of a Xbox presence state."""
@property @property
def state(self): def native_value(self):
"""Return the state of the requested attribute.""" """Return the state of the requested attribute."""
if not self.coordinator.last_update_success: if not self.coordinator.last_update_success:
return None return None

View file

@ -98,7 +98,7 @@ class XboxSensor(SensorEntity):
return False return False
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state

View file

@ -125,7 +125,7 @@ class XiaomiSensor(XiaomiDevice, SensorEntity):
return None return None
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any.""" """Return the unit of measurement of this entity, if any."""
try: try:
return SENSOR_TYPES.get(self._data_key)[0] return SENSOR_TYPES.get(self._data_key)[0]
@ -142,7 +142,7 @@ class XiaomiSensor(XiaomiDevice, SensorEntity):
) )
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state
@ -176,7 +176,7 @@ class XiaomiBatterySensor(XiaomiDevice, SensorEntity):
"""Representation of a XiaomiSensor.""" """Representation of a XiaomiSensor."""
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any.""" """Return the unit of measurement of this entity, if any."""
return PERCENTAGE return PERCENTAGE
@ -186,7 +186,7 @@ class XiaomiBatterySensor(XiaomiDevice, SensorEntity):
return DEVICE_CLASS_BATTERY return DEVICE_CLASS_BATTERY
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state

View file

@ -100,34 +100,34 @@ SENSOR_TYPES = {
ATTR_TEMPERATURE: XiaomiMiioSensorDescription( ATTR_TEMPERATURE: XiaomiMiioSensorDescription(
key=ATTR_TEMPERATURE, key=ATTR_TEMPERATURE,
name="Temperature", name="Temperature",
unit_of_measurement=TEMP_CELSIUS, native_unit_of_measurement=TEMP_CELSIUS,
device_class=DEVICE_CLASS_TEMPERATURE, device_class=DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
ATTR_HUMIDITY: XiaomiMiioSensorDescription( ATTR_HUMIDITY: XiaomiMiioSensorDescription(
key=ATTR_HUMIDITY, key=ATTR_HUMIDITY,
name="Humidity", name="Humidity",
unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
device_class=DEVICE_CLASS_HUMIDITY, device_class=DEVICE_CLASS_HUMIDITY,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
ATTR_PRESSURE: XiaomiMiioSensorDescription( ATTR_PRESSURE: XiaomiMiioSensorDescription(
key=ATTR_PRESSURE, key=ATTR_PRESSURE,
name="Pressure", name="Pressure",
unit_of_measurement=PRESSURE_HPA, native_unit_of_measurement=PRESSURE_HPA,
device_class=DEVICE_CLASS_PRESSURE, device_class=DEVICE_CLASS_PRESSURE,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
ATTR_LOAD_POWER: XiaomiMiioSensorDescription( ATTR_LOAD_POWER: XiaomiMiioSensorDescription(
key=ATTR_LOAD_POWER, key=ATTR_LOAD_POWER,
name="Load Power", name="Load Power",
unit_of_measurement=POWER_WATT, native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER, device_class=DEVICE_CLASS_POWER,
), ),
ATTR_WATER_LEVEL: XiaomiMiioSensorDescription( ATTR_WATER_LEVEL: XiaomiMiioSensorDescription(
key=ATTR_WATER_LEVEL, key=ATTR_WATER_LEVEL,
name="Water Level", name="Water Level",
unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
icon="mdi:water-check", icon="mdi:water-check",
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
valid_min_value=0.0, valid_min_value=0.0,
@ -136,27 +136,27 @@ SENSOR_TYPES = {
ATTR_ACTUAL_SPEED: XiaomiMiioSensorDescription( ATTR_ACTUAL_SPEED: XiaomiMiioSensorDescription(
key=ATTR_ACTUAL_SPEED, key=ATTR_ACTUAL_SPEED,
name="Actual Speed", name="Actual Speed",
unit_of_measurement="rpm", native_unit_of_measurement="rpm",
icon="mdi:fast-forward", icon="mdi:fast-forward",
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
ATTR_MOTOR_SPEED: XiaomiMiioSensorDescription( ATTR_MOTOR_SPEED: XiaomiMiioSensorDescription(
key=ATTR_MOTOR_SPEED, key=ATTR_MOTOR_SPEED,
name="Motor Speed", name="Motor Speed",
unit_of_measurement="rpm", native_unit_of_measurement="rpm",
icon="mdi:fast-forward", icon="mdi:fast-forward",
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
ATTR_ILLUMINANCE: XiaomiMiioSensorDescription( ATTR_ILLUMINANCE: XiaomiMiioSensorDescription(
key=ATTR_ILLUMINANCE, key=ATTR_ILLUMINANCE,
name="Illuminance", name="Illuminance",
unit_of_measurement=UNIT_LUMEN, native_unit_of_measurement=UNIT_LUMEN,
device_class=DEVICE_CLASS_ILLUMINANCE, device_class=DEVICE_CLASS_ILLUMINANCE,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
ATTR_AIR_QUALITY: XiaomiMiioSensorDescription( ATTR_AIR_QUALITY: XiaomiMiioSensorDescription(
key=ATTR_AIR_QUALITY, key=ATTR_AIR_QUALITY,
unit_of_measurement="AQI", native_unit_of_measurement="AQI",
icon="mdi:cloud", icon="mdi:cloud",
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
@ -331,7 +331,7 @@ class XiaomiAirQualityMonitor(XiaomiMiioEntity, SensorEntity):
return self._available return self._available
@property @property
def state(self): def native_value(self):
"""Return the state of the device.""" """Return the state of the device."""
return self._state return self._state
@ -378,7 +378,7 @@ class XiaomiGatewaySensor(XiaomiGatewayDevice, SensorEntity):
self.entity_description = description self.entity_description = description
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._sub_device.status[self.entity_description.key] return self._sub_device.status[self.entity_description.key]
@ -403,7 +403,7 @@ class XiaomiGatewayIlluminanceSensor(SensorEntity):
return self._available return self._available
@property @property
def state(self): def native_value(self):
"""Return the state of the device.""" """Return the state of the device."""
return self._state return self._state

View file

@ -37,11 +37,11 @@ class XS1Sensor(XS1DeviceEntity, SensorEntity):
return self.device.name() return self.device.name()
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self.device.value() return self.device.value()
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement.""" """Return the unit of measurement."""
return self.device.unit() return self.device.unit()

View file

@ -108,7 +108,7 @@ class DiscoverYandexTransport(SensorEntity):
self._attrs = attrs self._attrs = attrs
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state

View file

@ -94,12 +94,12 @@ class ZabbixTriggerCountSensor(SensorEntity):
return self._name return self._name
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the units of measurement.""" """Return the units of measurement."""
return "issues" return "issues"

View file

@ -171,12 +171,12 @@ class ZamgSensor(SensorEntity):
return f"{self.client_name} {self.variable}" return f"{self.client_name} {self.variable}"
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self.probe.get_data(self.variable) return self.probe.get_data(self.variable)
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any.""" """Return the unit of measurement of this entity, if any."""
return SENSOR_TYPES[self.variable][1] return SENSOR_TYPES[self.variable][1]

View file

@ -77,7 +77,7 @@ class ZestimateDataSensor(SensorEntity):
return f"{self._name} {self.address}" return f"{self._name} {self.address}"
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
try: try:
return round(float(self._state), 1) return round(float(self._state), 1)

View file

@ -135,12 +135,12 @@ class Sensor(ZhaEntity, SensorEntity):
return self._state_class return self._state_class
@property @property
def unit_of_measurement(self) -> str | None: def native_unit_of_measurement(self) -> str | None:
"""Return the unit of measurement of this entity.""" """Return the unit of measurement of this entity."""
return self._unit return self._unit
@property @property
def state(self) -> StateType: def native_value(self) -> StateType:
"""Return the state of the entity.""" """Return the state of the entity."""
assert self.SENSOR_ATTR is not None assert self.SENSOR_ATTR is not None
raw_state = self._channel.cluster.get(self.SENSOR_ATTR) raw_state = self._channel.cluster.get(self.SENSOR_ATTR)
@ -274,7 +274,7 @@ class SmartEnergyMetering(Sensor):
return self._channel.formatter_function(value) return self._channel.formatter_function(value)
@property @property
def unit_of_measurement(self) -> str: def native_unit_of_measurement(self) -> str:
"""Return Unit of measurement.""" """Return Unit of measurement."""
return self._channel.unit_of_measurement return self._channel.unit_of_measurement

View file

@ -196,7 +196,7 @@ class ZodiacSensor(SensorEntity):
return "zodiac__sign" return "zodiac__sign"
@property @property
def state(self) -> str: def native_value(self) -> str:
"""Return the state of the device.""" """Return the state of the device."""
return self._state return self._state

View file

@ -71,7 +71,7 @@ class ZMSensorMonitors(SensorEntity):
return f"{self._monitor.name} Status" return f"{self._monitor.name} Status"
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state
@ -107,12 +107,12 @@ class ZMSensorEvents(SensorEntity):
return f"{self._monitor.name} {self.time_period.title}" return f"{self._monitor.name} {self.time_period.title}"
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any.""" """Return the unit of measurement of this entity, if any."""
return "Events" return "Events"
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state
@ -136,7 +136,7 @@ class ZMSensorRunState(SensorEntity):
return "Run State" return "Run State"
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state

View file

@ -56,12 +56,12 @@ class ZWaveSensor(ZWaveDeviceEntity, SensorEntity):
return True return True
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement the value is expressed in.""" """Return the unit of measurement the value is expressed in."""
return self._units return self._units
@ -70,7 +70,7 @@ class ZWaveMultilevelSensor(ZWaveSensor):
"""Representation of a multi level sensor Z-Wave sensor.""" """Representation of a multi level sensor Z-Wave sensor."""
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
if self._units in ("C", "F"): if self._units in ("C", "F"):
return round(self._state, 1) return round(self._state, 1)
@ -87,7 +87,7 @@ class ZWaveMultilevelSensor(ZWaveSensor):
return None return None
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit the value is expressed in.""" """Return the unit the value is expressed in."""
if self._units == "C": if self._units == "C":
return TEMP_CELSIUS return TEMP_CELSIUS

View file

@ -181,14 +181,14 @@ class ZWaveStringSensor(ZwaveSensorBase):
"""Representation of a Z-Wave String sensor.""" """Representation of a Z-Wave String sensor."""
@property @property
def state(self) -> str | None: def native_value(self) -> str | None:
"""Return state of the sensor.""" """Return state of the sensor."""
if self.info.primary_value.value is None: if self.info.primary_value.value is None:
return None return None
return str(self.info.primary_value.value) return str(self.info.primary_value.value)
@property @property
def unit_of_measurement(self) -> str | None: def native_unit_of_measurement(self) -> str | None:
"""Return unit of measurement the value is expressed in.""" """Return unit of measurement the value is expressed in."""
if self.info.primary_value.metadata.unit is None: if self.info.primary_value.metadata.unit is None:
return None return None
@ -215,14 +215,14 @@ class ZWaveNumericSensor(ZwaveSensorBase):
) )
@property @property
def state(self) -> float: def native_value(self) -> float:
"""Return state of the sensor.""" """Return state of the sensor."""
if self.info.primary_value.value is None: if self.info.primary_value.value is None:
return 0 return 0
return round(float(self.info.primary_value.value), 2) return round(float(self.info.primary_value.value), 2)
@property @property
def unit_of_measurement(self) -> str | None: def native_unit_of_measurement(self) -> str | None:
"""Return unit of measurement the value is expressed in.""" """Return unit of measurement the value is expressed in."""
if self.info.primary_value.metadata.unit is None: if self.info.primary_value.metadata.unit is None:
return None return None
@ -345,7 +345,7 @@ class ZWaveListSensor(ZwaveSensorBase):
) )
@property @property
def state(self) -> str | None: def native_value(self) -> str | None:
"""Return state of the sensor.""" """Return state of the sensor."""
if self.info.primary_value.value is None: if self.info.primary_value.value is None:
return None return None
@ -387,7 +387,7 @@ class ZWaveConfigParameterSensor(ZwaveSensorBase):
) )
@property @property
def state(self) -> str | None: def native_value(self) -> str | None:
"""Return state of the sensor.""" """Return state of the sensor."""
if self.info.primary_value.value is None: if self.info.primary_value.value is None:
return None return None
@ -439,7 +439,7 @@ class ZWaveNodeStatusSensor(SensorEntity):
self._attr_device_info = { self._attr_device_info = {
"identifiers": {get_device_id(self.client, self.node)}, "identifiers": {get_device_id(self.client, self.node)},
} }
self._attr_state: str = node.status.name.lower() self._attr_native_value: str = node.status.name.lower()
async def async_poll_value(self, _: bool) -> None: async def async_poll_value(self, _: bool) -> None:
"""Poll a value.""" """Poll a value."""
@ -447,7 +447,7 @@ class ZWaveNodeStatusSensor(SensorEntity):
def _status_changed(self, _: dict) -> None: def _status_changed(self, _: dict) -> None:
"""Call when status event is received.""" """Call when status event is received."""
self._attr_state = self.node.status.name.lower() self._attr_native_value = self.node.status.name.lower()
self.async_write_ha_state() self.async_write_ha_state()
async def async_added_to_hass(self) -> None: async def async_added_to_hass(self) -> None:

View file

@ -29,6 +29,7 @@ class TestVultrSensorSetup(unittest.TestCase):
def add_entities(self, devices, action): def add_entities(self, devices, action):
"""Mock add devices.""" """Mock add devices."""
for device in devices: for device in devices:
device.hass = self.hass
self.DEVICES.append(device) self.DEVICES.append(device)
def setUp(self): def setUp(self):

View file

@ -35,6 +35,9 @@ async def test_setup(hass, requests_mock):
def add_entities(new_entities, update_before_add=False): def add_entities(new_entities, update_before_add=False):
"""Mock add entities.""" """Mock add entities."""
for entity in new_entities:
entity.hass = hass
if update_before_add: if update_before_add:
for entity in new_entities: for entity in new_entities:
entity.update() entity.update()

View file

@ -70,8 +70,10 @@ def test_get_device_detects_battery_sensor(mock_openzwave):
assert device.device_class == homeassistant.const.DEVICE_CLASS_BATTERY assert device.device_class == homeassistant.const.DEVICE_CLASS_BATTERY
def test_multilevelsensor_value_changed_temp_fahrenheit(mock_openzwave): def test_multilevelsensor_value_changed_temp_fahrenheit(hass, mock_openzwave):
"""Test value changed for Z-Wave multilevel sensor for temperature.""" """Test value changed for Z-Wave multilevel sensor for temperature."""
hass.config.units.temperature_unit = homeassistant.const.TEMP_FAHRENHEIT
node = MockNode( node = MockNode(
command_classes=[ command_classes=[
const.COMMAND_CLASS_SENSOR_MULTILEVEL, const.COMMAND_CLASS_SENSOR_MULTILEVEL,
@ -82,6 +84,7 @@ def test_multilevelsensor_value_changed_temp_fahrenheit(mock_openzwave):
values = MockEntityValues(primary=value) values = MockEntityValues(primary=value)
device = sensor.get_device(node=node, values=values, node_config={}) device = sensor.get_device(node=node, values=values, node_config={})
device.hass = hass
assert device.state == 191.0 assert device.state == 191.0
assert device.unit_of_measurement == homeassistant.const.TEMP_FAHRENHEIT assert device.unit_of_measurement == homeassistant.const.TEMP_FAHRENHEIT
assert device.device_class == homeassistant.const.DEVICE_CLASS_TEMPERATURE assert device.device_class == homeassistant.const.DEVICE_CLASS_TEMPERATURE
@ -90,8 +93,9 @@ def test_multilevelsensor_value_changed_temp_fahrenheit(mock_openzwave):
assert device.state == 198.0 assert device.state == 198.0
def test_multilevelsensor_value_changed_temp_celsius(mock_openzwave): def test_multilevelsensor_value_changed_temp_celsius(hass, mock_openzwave):
"""Test value changed for Z-Wave multilevel sensor for temperature.""" """Test value changed for Z-Wave multilevel sensor for temperature."""
hass.config.units.temperature_unit = homeassistant.const.TEMP_CELSIUS
node = MockNode( node = MockNode(
command_classes=[ command_classes=[
const.COMMAND_CLASS_SENSOR_MULTILEVEL, const.COMMAND_CLASS_SENSOR_MULTILEVEL,
@ -102,6 +106,7 @@ def test_multilevelsensor_value_changed_temp_celsius(mock_openzwave):
values = MockEntityValues(primary=value) values = MockEntityValues(primary=value)
device = sensor.get_device(node=node, values=values, node_config={}) device = sensor.get_device(node=node, values=values, node_config={})
device.hass = hass
assert device.state == 38.9 assert device.state == 38.9
assert device.unit_of_measurement == homeassistant.const.TEMP_CELSIUS assert device.unit_of_measurement == homeassistant.const.TEMP_CELSIUS
assert device.device_class == homeassistant.const.DEVICE_CLASS_TEMPERATURE assert device.device_class == homeassistant.const.DEVICE_CLASS_TEMPERATURE
@ -110,7 +115,7 @@ def test_multilevelsensor_value_changed_temp_celsius(mock_openzwave):
assert device.state == 38.0 assert device.state == 38.0
def test_multilevelsensor_value_changed_other_units(mock_openzwave): def test_multilevelsensor_value_changed_other_units(hass, mock_openzwave):
"""Test value changed for Z-Wave multilevel sensor for other units.""" """Test value changed for Z-Wave multilevel sensor for other units."""
node = MockNode( node = MockNode(
command_classes=[ command_classes=[
@ -124,6 +129,7 @@ def test_multilevelsensor_value_changed_other_units(mock_openzwave):
values = MockEntityValues(primary=value) values = MockEntityValues(primary=value)
device = sensor.get_device(node=node, values=values, node_config={}) device = sensor.get_device(node=node, values=values, node_config={})
device.hass = hass
assert device.state == 190.96 assert device.state == 190.96
assert device.unit_of_measurement == homeassistant.const.ENERGY_KILO_WATT_HOUR assert device.unit_of_measurement == homeassistant.const.ENERGY_KILO_WATT_HOUR
assert device.device_class is None assert device.device_class is None
@ -132,7 +138,7 @@ def test_multilevelsensor_value_changed_other_units(mock_openzwave):
assert device.state == 197.96 assert device.state == 197.96
def test_multilevelsensor_value_changed_integer(mock_openzwave): def test_multilevelsensor_value_changed_integer(hass, mock_openzwave):
"""Test value changed for Z-Wave multilevel sensor for other units.""" """Test value changed for Z-Wave multilevel sensor for other units."""
node = MockNode( node = MockNode(
command_classes=[ command_classes=[
@ -144,6 +150,7 @@ def test_multilevelsensor_value_changed_integer(mock_openzwave):
values = MockEntityValues(primary=value) values = MockEntityValues(primary=value)
device = sensor.get_device(node=node, values=values, node_config={}) device = sensor.get_device(node=node, values=values, node_config={})
device.hass = hass
assert device.state == 5 assert device.state == 5
assert device.unit_of_measurement == "counts" assert device.unit_of_measurement == "counts"
assert device.device_class is None assert device.device_class is None
@ -152,7 +159,7 @@ def test_multilevelsensor_value_changed_integer(mock_openzwave):
assert device.state == 6 assert device.state == 6
def test_alarm_sensor_value_changed(mock_openzwave): def test_alarm_sensor_value_changed(hass, mock_openzwave):
"""Test value changed for Z-Wave sensor.""" """Test value changed for Z-Wave sensor."""
node = MockNode( node = MockNode(
command_classes=[const.COMMAND_CLASS_ALARM, const.COMMAND_CLASS_SENSOR_ALARM] command_classes=[const.COMMAND_CLASS_ALARM, const.COMMAND_CLASS_SENSOR_ALARM]
@ -161,6 +168,7 @@ def test_alarm_sensor_value_changed(mock_openzwave):
values = MockEntityValues(primary=value) values = MockEntityValues(primary=value)
device = sensor.get_device(node=node, values=values, node_config={}) device = sensor.get_device(node=node, values=values, node_config={})
device.hass = hass
assert device.state == 12.34 assert device.state == 12.34
assert device.unit_of_measurement == homeassistant.const.PERCENTAGE assert device.unit_of_measurement == homeassistant.const.PERCENTAGE
assert device.device_class is None assert device.device_class is None