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

This commit is contained in:
Erik Montnemery 2021-08-12 13:26:17 +02:00 committed by GitHub
parent e55868b17f
commit 103e21c278
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
65 changed files with 289 additions and 288 deletions

View File

@ -65,133 +65,133 @@ SENSORS: Final[tuple[SensorEntityDescription, ...]] = (
SensorEntityDescription(
key=ATTR_BME280_HUMIDITY,
name=f"{DEFAULT_NAME} BME280 Humidity",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
device_class=DEVICE_CLASS_HUMIDITY,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_BME280_PRESSURE,
name=f"{DEFAULT_NAME} BME280 Pressure",
unit_of_measurement=PRESSURE_HPA,
native_unit_of_measurement=PRESSURE_HPA,
device_class=DEVICE_CLASS_PRESSURE,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_BME280_TEMPERATURE,
name=f"{DEFAULT_NAME} BME280 Temperature",
unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=TEMP_CELSIUS,
device_class=DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_BMP280_PRESSURE,
name=f"{DEFAULT_NAME} BMP280 Pressure",
unit_of_measurement=PRESSURE_HPA,
native_unit_of_measurement=PRESSURE_HPA,
device_class=DEVICE_CLASS_PRESSURE,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_BMP280_TEMPERATURE,
name=f"{DEFAULT_NAME} BMP280 Temperature",
unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=TEMP_CELSIUS,
device_class=DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_HECA_HUMIDITY,
name=f"{DEFAULT_NAME} HECA Humidity",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
device_class=DEVICE_CLASS_HUMIDITY,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_HECA_TEMPERATURE,
name=f"{DEFAULT_NAME} HECA Temperature",
unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=TEMP_CELSIUS,
device_class=DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_MHZ14A_CARBON_DIOXIDE,
name=f"{DEFAULT_NAME} MH-Z14A Carbon Dioxide",
unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
device_class=DEVICE_CLASS_CO2,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_SDS011_P1,
name=f"{DEFAULT_NAME} SDS011 Particulate Matter 10",
unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
icon="mdi:blur",
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_SDS011_P2,
name=f"{DEFAULT_NAME} SDS011 Particulate Matter 2.5",
unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
icon="mdi:blur",
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_SHT3X_HUMIDITY,
name=f"{DEFAULT_NAME} SHT3X Humidity",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
device_class=DEVICE_CLASS_HUMIDITY,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_SHT3X_TEMPERATURE,
name=f"{DEFAULT_NAME} SHT3X Temperature",
unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=TEMP_CELSIUS,
device_class=DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_SPS30_P0,
name=f"{DEFAULT_NAME} SPS30 Particulate Matter 1.0",
unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
icon="mdi:blur",
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_SPS30_P1,
name=f"{DEFAULT_NAME} SPS30 Particulate Matter 10",
unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
icon="mdi:blur",
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_SPS30_P2,
name=f"{DEFAULT_NAME} SPS30 Particulate Matter 2.5",
unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
icon="mdi:blur",
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_SPS30_P4,
name=f"{DEFAULT_NAME} SPS30 Particulate Matter 4.0",
unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
icon="mdi:blur",
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_DHT22_HUMIDITY,
name=f"{DEFAULT_NAME} DHT22 Humidity",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
device_class=DEVICE_CLASS_HUMIDITY,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_DHT22_TEMPERATURE,
name=f"{DEFAULT_NAME} DHT22 Temperature",
unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=TEMP_CELSIUS,
device_class=DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
key=ATTR_SIGNAL_STRENGTH,
name=f"{DEFAULT_NAME} Signal Strength",
unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,

View File

@ -75,7 +75,7 @@ class NAMSensor(CoordinatorEntity, SensorEntity):
self.entity_description = description
@property
def state(self) -> StateType:
def native_value(self) -> StateType:
"""Return the state."""
return cast(
StateType, getattr(self.coordinator.data, self.entity_description.key)
@ -99,7 +99,7 @@ class NAMSensorUptime(NAMSensor):
"""Define an Nettigo Air Monitor uptime sensor."""
@property
def state(self) -> str:
def native_value(self) -> str:
"""Return the state."""
uptime_sec = getattr(self.coordinator.data, self.entity_description.key)
return (

View File

@ -89,14 +89,14 @@ class NeatoSensor(SensorEntity):
return self._available
@property
def state(self) -> str | None:
def native_value(self) -> str | None:
"""Return the state."""
if self._state is not None:
return str(self._state["details"]["charge"])
return None
@property
def unit_of_measurement(self) -> str:
def native_unit_of_measurement(self) -> str:
"""Return unit of measurement."""
return PERCENTAGE

View File

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

View File

@ -154,12 +154,12 @@ class NestBasicSensor(NestSensorDevice, SensorEntity):
"""Representation a basic Nest sensor."""
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self._unit
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._state
@ -189,12 +189,12 @@ class NestTempSensor(NestSensorDevice, SensorEntity):
"""Representation of a Nest Temperature sensor."""
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._state
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self._unit

View File

@ -95,13 +95,13 @@ class TemperatureSensor(SensorBase):
return f"{self._device_info.device_name} Temperature"
@property
def state(self) -> float:
def native_value(self) -> float:
"""Return the state of the sensor."""
trait: TemperatureTrait = self._device.traits[TemperatureTrait.NAME]
return trait.ambient_temperature_celsius
@property
def unit_of_measurement(self) -> str:
def native_unit_of_measurement(self) -> str:
"""Return the unit of measurement."""
return TEMP_CELSIUS
@ -126,13 +126,13 @@ class HumiditySensor(SensorBase):
return f"{self._device_info.device_name} Humidity"
@property
def state(self) -> float:
def native_value(self) -> float:
"""Return the state of the sensor."""
trait: HumidityTrait = self._device.traits[HumidityTrait.NAME]
return trait.ambient_humidity_percent
@property
def unit_of_measurement(self) -> str:
def native_unit_of_measurement(self) -> str:
"""Return the unit of measurement."""
return PERCENTAGE

View File

@ -83,7 +83,7 @@ SENSOR_TYPES: tuple[NetatmoSensorEntityDescription, ...] = (
name="Temperature",
netatmo_name="Temperature",
entity_registry_enabled_default=True,
unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=TEMP_CELSIUS,
device_class=DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT,
),
@ -98,7 +98,7 @@ SENSOR_TYPES: tuple[NetatmoSensorEntityDescription, ...] = (
key="co2",
name="CO2",
netatmo_name="CO2",
unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
entity_registry_enabled_default=True,
device_class=DEVICE_CLASS_CO2,
state_class=STATE_CLASS_MEASUREMENT,
@ -108,7 +108,7 @@ SENSOR_TYPES: tuple[NetatmoSensorEntityDescription, ...] = (
name="Pressure",
netatmo_name="Pressure",
entity_registry_enabled_default=True,
unit_of_measurement=PRESSURE_MBAR,
native_unit_of_measurement=PRESSURE_MBAR,
device_class=DEVICE_CLASS_PRESSURE,
state_class=STATE_CLASS_MEASUREMENT,
),
@ -124,7 +124,7 @@ SENSOR_TYPES: tuple[NetatmoSensorEntityDescription, ...] = (
name="Noise",
netatmo_name="Noise",
entity_registry_enabled_default=True,
unit_of_measurement=SOUND_PRESSURE_DB,
native_unit_of_measurement=SOUND_PRESSURE_DB,
icon="mdi:volume-high",
state_class=STATE_CLASS_MEASUREMENT,
),
@ -133,7 +133,7 @@ SENSOR_TYPES: tuple[NetatmoSensorEntityDescription, ...] = (
name="Humidity",
netatmo_name="Humidity",
entity_registry_enabled_default=True,
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
device_class=DEVICE_CLASS_HUMIDITY,
state_class=STATE_CLASS_MEASUREMENT,
),
@ -142,7 +142,7 @@ SENSOR_TYPES: tuple[NetatmoSensorEntityDescription, ...] = (
name="Rain",
netatmo_name="Rain",
entity_registry_enabled_default=True,
unit_of_measurement=LENGTH_MILLIMETERS,
native_unit_of_measurement=LENGTH_MILLIMETERS,
icon="mdi:weather-rainy",
),
NetatmoSensorEntityDescription(
@ -150,7 +150,7 @@ SENSOR_TYPES: tuple[NetatmoSensorEntityDescription, ...] = (
name="Rain last hour",
netatmo_name="sum_rain_1",
entity_registry_enabled_default=False,
unit_of_measurement=LENGTH_MILLIMETERS,
native_unit_of_measurement=LENGTH_MILLIMETERS,
icon="mdi:weather-rainy",
),
NetatmoSensorEntityDescription(
@ -158,7 +158,7 @@ SENSOR_TYPES: tuple[NetatmoSensorEntityDescription, ...] = (
name="Rain today",
netatmo_name="sum_rain_24",
entity_registry_enabled_default=True,
unit_of_measurement=LENGTH_MILLIMETERS,
native_unit_of_measurement=LENGTH_MILLIMETERS,
icon="mdi:weather-rainy",
),
NetatmoSensorEntityDescription(
@ -166,7 +166,7 @@ SENSOR_TYPES: tuple[NetatmoSensorEntityDescription, ...] = (
name="Battery Percent",
netatmo_name="battery_percent",
entity_registry_enabled_default=True,
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT,
),
@ -182,7 +182,7 @@ SENSOR_TYPES: tuple[NetatmoSensorEntityDescription, ...] = (
name="Angle",
netatmo_name="WindAngle",
entity_registry_enabled_default=False,
unit_of_measurement=DEGREE,
native_unit_of_measurement=DEGREE,
icon="mdi:compass-outline",
state_class=STATE_CLASS_MEASUREMENT,
),
@ -191,7 +191,7 @@ SENSOR_TYPES: tuple[NetatmoSensorEntityDescription, ...] = (
name="Wind Strength",
netatmo_name="WindStrength",
entity_registry_enabled_default=True,
unit_of_measurement=SPEED_KILOMETERS_PER_HOUR,
native_unit_of_measurement=SPEED_KILOMETERS_PER_HOUR,
icon="mdi:weather-windy",
state_class=STATE_CLASS_MEASUREMENT,
),
@ -207,7 +207,7 @@ SENSOR_TYPES: tuple[NetatmoSensorEntityDescription, ...] = (
name="Gust Angle",
netatmo_name="GustAngle",
entity_registry_enabled_default=False,
unit_of_measurement=DEGREE,
native_unit_of_measurement=DEGREE,
icon="mdi:compass-outline",
state_class=STATE_CLASS_MEASUREMENT,
),
@ -216,7 +216,7 @@ SENSOR_TYPES: tuple[NetatmoSensorEntityDescription, ...] = (
name="Gust Strength",
netatmo_name="GustStrength",
entity_registry_enabled_default=False,
unit_of_measurement=SPEED_KILOMETERS_PER_HOUR,
native_unit_of_measurement=SPEED_KILOMETERS_PER_HOUR,
icon="mdi:weather-windy",
state_class=STATE_CLASS_MEASUREMENT,
),
@ -239,7 +239,7 @@ SENSOR_TYPES: tuple[NetatmoSensorEntityDescription, ...] = (
name="Radio Level",
netatmo_name="rf_status",
entity_registry_enabled_default=False,
unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
state_class=STATE_CLASS_MEASUREMENT,
),
@ -255,7 +255,7 @@ SENSOR_TYPES: tuple[NetatmoSensorEntityDescription, ...] = (
name="Wifi Level",
netatmo_name="wifi_status",
entity_registry_enabled_default=False,
unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
state_class=STATE_CLASS_MEASUREMENT,
),
@ -518,25 +518,25 @@ class NetatmoSensor(NetatmoBase, SensorEntity):
self._device_name,
self._id,
)
self._attr_state = None
self._attr_native_value = None
return
try:
state = data[self.entity_description.netatmo_name]
if self.entity_description.key in {"temperature", "pressure", "sum_rain_1"}:
self._attr_state = round(state, 1)
self._attr_native_value = round(state, 1)
elif self.entity_description.key in {"windangle_value", "gustangle_value"}:
self._attr_state = fix_angle(state)
self._attr_native_value = fix_angle(state)
elif self.entity_description.key in {"windangle", "gustangle"}:
self._attr_state = process_angle(fix_angle(state))
self._attr_native_value = process_angle(fix_angle(state))
elif self.entity_description.key == "rf_status":
self._attr_state = process_rf(state)
self._attr_native_value = process_rf(state)
elif self.entity_description.key == "wifi_status":
self._attr_state = process_wifi(state)
self._attr_native_value = process_wifi(state)
elif self.entity_description.key == "health_idx":
self._attr_state = process_health(state)
self._attr_native_value = process_health(state)
else:
self._attr_state = state
self._attr_native_value = state
except KeyError:
if self.state:
_LOGGER.debug(
@ -544,7 +544,7 @@ class NetatmoSensor(NetatmoBase, SensorEntity):
self.entity_description.key,
self._device_name,
)
self._attr_state = None
self._attr_native_value = None
return
self.async_write_ha_state()
@ -758,14 +758,14 @@ class NetatmoPublicSensor(NetatmoBase, SensorEntity):
self.entity_description.key,
self._area_name,
)
self._attr_state = None
self._attr_native_value = None
return
if values := [x for x in data.values() if x is not None]:
if self._mode == "avg":
self._attr_state = round(sum(values) / len(values), 1)
self._attr_native_value = round(sum(values) / len(values), 1)
elif self._mode == "max":
self._attr_state = max(values)
self._attr_native_value = max(values)
self._attr_available = self.state is not None
self.async_write_ha_state()

View File

@ -117,7 +117,7 @@ class NetdataSensor(SensorEntity):
return f"{self._name} {self._sensor_name}"
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self._unit_of_measurement
@ -127,7 +127,7 @@ class NetdataSensor(SensorEntity):
return self._icon
@property
def state(self):
def native_value(self):
"""Return the state of the resources."""
return self._state
@ -162,7 +162,7 @@ class NetdataAlarms(SensorEntity):
return f"{self._name} Alarms"
@property
def state(self):
def native_value(self):
"""Return the state of the resources."""
return self._state

View File

@ -37,7 +37,7 @@ class LTESensor(LTEEntity, SensorEntity):
"""Base LTE sensor entity."""
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement."""
return SENSOR_UNITS[self.sensor_type]
@ -46,7 +46,7 @@ class SMSUnreadSensor(LTESensor):
"""Unread SMS sensor entity."""
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return sum(1 for x in self.modem_data.data.sms if x.unread)
@ -55,7 +55,7 @@ class SMSTotalSensor(LTESensor):
"""Total SMS sensor entity."""
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return len(self.modem_data.data.sms)
@ -64,7 +64,7 @@ class UsageSensor(LTESensor):
"""Data usage sensor entity."""
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return round(self.modem_data.data.usage / 1024 ** 2, 1)
@ -73,6 +73,6 @@ class GenericSensor(LTESensor):
"""Sensor entity with raw state."""
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return getattr(self.modem_data.data, self.sensor_type)

View File

@ -149,12 +149,12 @@ class NeurioEnergy(SensorEntity):
return self._name
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._state
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement

View File

@ -182,7 +182,7 @@ class NexiaThermostatSensor(NexiaThermostatEntity, SensorEntity):
return self._class
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
val = getattr(self._thermostat, self._call)()
if self._modifier:
@ -192,7 +192,7 @@ class NexiaThermostatSensor(NexiaThermostatEntity, SensorEntity):
return val
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement this sensor expresses itself in."""
return self._unit_of_measurement
@ -230,7 +230,7 @@ class NexiaThermostatZoneSensor(NexiaThermostatZoneEntity, SensorEntity):
return self._class
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
val = getattr(self._zone, self._call)()
if self._modifier:
@ -240,6 +240,6 @@ class NexiaThermostatZoneSensor(NexiaThermostatZoneEntity, SensorEntity):
return val
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement this sensor expresses itself in."""
return self._unit_of_measurement

View File

@ -146,7 +146,7 @@ class NextBusDepartureSensor(SensorEntity):
return self._name
@property
def state(self):
def native_value(self):
"""Return current state of the sensor."""
return self._state

View File

@ -34,7 +34,7 @@ class NextcloudSensor(SensorEntity):
return self._name
@property
def state(self):
def native_value(self):
"""Return the state for this sensor."""
return self._state

View File

@ -58,7 +58,7 @@ class NightscoutSensor(SensorEntity):
return self._name
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self._unit_of_measurement
@ -68,7 +68,7 @@ class NightscoutSensor(SensorEntity):
return self._available
@property
def state(self):
def native_value(self):
"""Return the state of the device."""
return self._state

View File

@ -50,12 +50,12 @@ class LeafBatterySensor(LeafEntity, SensorEntity):
return DEVICE_CLASS_BATTERY
@property
def state(self):
def native_value(self):
"""Battery state percentage."""
return round(self.car.data[DATA_BATTERY])
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Battery state measured in percentage."""
return PERCENTAGE
@ -89,7 +89,7 @@ class LeafRangeSensor(LeafEntity, SensorEntity):
)
@property
def state(self):
def native_value(self):
"""Battery range in miles or kms."""
if self._ac_on:
ret = self.car.data[DATA_RANGE_AC]
@ -102,7 +102,7 @@ class LeafRangeSensor(LeafEntity, SensorEntity):
return round(ret)
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Battery range unit."""
if not self.car.hass.config.units.is_metric or self.car.force_miles:
return LENGTH_MILES

View File

@ -120,7 +120,7 @@ class NMBSLiveBoard(SensorEntity):
return DEFAULT_ICON
@property
def state(self):
def native_value(self):
"""Return sensor state."""
return self._state
@ -166,7 +166,7 @@ class NMBSLiveBoard(SensorEntity):
class NMBSSensor(SensorEntity):
"""Get the the total travel time for a given connection."""
_attr_unit_of_measurement = TIME_MINUTES
_attr_native_unit_of_measurement = TIME_MINUTES
def __init__(
self, api_client, name, show_on_map, station_from, station_to, excl_vias
@ -238,7 +238,7 @@ class NMBSSensor(SensorEntity):
return attrs
@property
def state(self):
def native_value(self):
"""Return the state of the device."""
return self._state

View File

@ -107,7 +107,7 @@ class NOAATidesAndCurrentsSensor(SensorEntity):
return attr
@property
def state(self):
def native_value(self):
"""Return the state of the device."""
if self.data is None:
return None

View File

@ -63,7 +63,7 @@ class NotionSensor(NotionEntity, SensorEntity):
coordinator, task_id, sensor_id, bridge_id, system_id, name, device_class
)
self._attr_unit_of_measurement = unit
self._attr_native_unit_of_measurement = unit
@callback
def _async_update_from_latest_data(self) -> None:
@ -71,7 +71,7 @@ class NotionSensor(NotionEntity, SensorEntity):
task = self.coordinator.data["tasks"][self._task_id]
if task["task_type"] == SENSOR_TEMPERATURE:
self._attr_state = round(float(task["status"]["value"]), 1)
self._attr_native_value = round(float(task["status"]["value"]), 1)
else:
LOGGER.error(
"Unknown task type: %s: %s",

View File

@ -99,7 +99,7 @@ class StationPriceSensor(CoordinatorEntity, SensorEntity):
return f"{station_name} {self._fuel_type}"
@property
def state(self) -> float | None:
def native_value(self) -> float | None:
"""Return the state of the sensor."""
if self.coordinator.data is None:
return None
@ -117,7 +117,7 @@ class StationPriceSensor(CoordinatorEntity, SensorEntity):
}
@property
def unit_of_measurement(self) -> str:
def native_unit_of_measurement(self) -> str:
"""Return the units of measurement."""
return f"{CURRENCY_CENT}/{VOLUME_LITERS}"

View File

@ -78,12 +78,12 @@ class NumatoGpioAdc(SensorEntity):
return self._name
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._state
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self._unit_of_measurement

View File

@ -51,7 +51,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.status.display": SensorEntityDescription(
key="ups.status.display",
name="Status",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:information-outline",
device_class=None,
state_class=None,
@ -59,7 +59,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.status": SensorEntityDescription(
key="ups.status",
name="Status Data",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:information-outline",
device_class=None,
state_class=None,
@ -67,7 +67,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.alarm": SensorEntityDescription(
key="ups.alarm",
name="Alarms",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:alarm",
device_class=None,
state_class=None,
@ -75,7 +75,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.temperature": SensorEntityDescription(
key="ups.temperature",
name="UPS Temperature",
unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=TEMP_CELSIUS,
icon=None,
device_class=DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT,
@ -83,7 +83,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.load": SensorEntityDescription(
key="ups.load",
name="Load",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
icon="mdi:gauge",
device_class=None,
state_class=STATE_CLASS_MEASUREMENT,
@ -91,7 +91,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.load.high": SensorEntityDescription(
key="ups.load.high",
name="Overload Setting",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
icon="mdi:gauge",
device_class=None,
state_class=None,
@ -99,7 +99,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.id": SensorEntityDescription(
key="ups.id",
name="System identifier",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:information-outline",
device_class=None,
state_class=None,
@ -107,7 +107,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.delay.start": SensorEntityDescription(
key="ups.delay.start",
name="Load Restart Delay",
unit_of_measurement=TIME_SECONDS,
native_unit_of_measurement=TIME_SECONDS,
icon="mdi:timer-outline",
device_class=None,
state_class=None,
@ -115,7 +115,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.delay.reboot": SensorEntityDescription(
key="ups.delay.reboot",
name="UPS Reboot Delay",
unit_of_measurement=TIME_SECONDS,
native_unit_of_measurement=TIME_SECONDS,
icon="mdi:timer-outline",
device_class=None,
state_class=None,
@ -123,7 +123,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.delay.shutdown": SensorEntityDescription(
key="ups.delay.shutdown",
name="UPS Shutdown Delay",
unit_of_measurement=TIME_SECONDS,
native_unit_of_measurement=TIME_SECONDS,
icon="mdi:timer-outline",
device_class=None,
state_class=None,
@ -131,7 +131,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.timer.start": SensorEntityDescription(
key="ups.timer.start",
name="Load Start Timer",
unit_of_measurement=TIME_SECONDS,
native_unit_of_measurement=TIME_SECONDS,
icon="mdi:timer-outline",
device_class=None,
state_class=None,
@ -139,7 +139,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.timer.reboot": SensorEntityDescription(
key="ups.timer.reboot",
name="Load Reboot Timer",
unit_of_measurement=TIME_SECONDS,
native_unit_of_measurement=TIME_SECONDS,
icon="mdi:timer-outline",
device_class=None,
state_class=None,
@ -147,7 +147,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.timer.shutdown": SensorEntityDescription(
key="ups.timer.shutdown",
name="Load Shutdown Timer",
unit_of_measurement=TIME_SECONDS,
native_unit_of_measurement=TIME_SECONDS,
icon="mdi:timer-outline",
device_class=None,
state_class=None,
@ -155,7 +155,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.test.interval": SensorEntityDescription(
key="ups.test.interval",
name="Self-Test Interval",
unit_of_measurement=TIME_SECONDS,
native_unit_of_measurement=TIME_SECONDS,
icon="mdi:timer-outline",
device_class=None,
state_class=None,
@ -163,7 +163,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.test.result": SensorEntityDescription(
key="ups.test.result",
name="Self-Test Result",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:information-outline",
device_class=None,
state_class=None,
@ -171,7 +171,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.test.date": SensorEntityDescription(
key="ups.test.date",
name="Self-Test Date",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:calendar",
device_class=None,
state_class=None,
@ -179,7 +179,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.display.language": SensorEntityDescription(
key="ups.display.language",
name="Language",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:information-outline",
device_class=None,
state_class=None,
@ -187,7 +187,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.contacts": SensorEntityDescription(
key="ups.contacts",
name="External Contacts",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:information-outline",
device_class=None,
state_class=None,
@ -195,7 +195,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.efficiency": SensorEntityDescription(
key="ups.efficiency",
name="Efficiency",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
icon="mdi:gauge",
device_class=None,
state_class=STATE_CLASS_MEASUREMENT,
@ -203,7 +203,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.power": SensorEntityDescription(
key="ups.power",
name="Current Apparent Power",
unit_of_measurement=POWER_VOLT_AMPERE,
native_unit_of_measurement=POWER_VOLT_AMPERE,
icon="mdi:flash",
device_class=None,
state_class=STATE_CLASS_MEASUREMENT,
@ -211,7 +211,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.power.nominal": SensorEntityDescription(
key="ups.power.nominal",
name="Nominal Power",
unit_of_measurement=POWER_VOLT_AMPERE,
native_unit_of_measurement=POWER_VOLT_AMPERE,
icon="mdi:flash",
device_class=None,
state_class=None,
@ -219,7 +219,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.realpower": SensorEntityDescription(
key="ups.realpower",
name="Current Real Power",
unit_of_measurement=POWER_WATT,
native_unit_of_measurement=POWER_WATT,
icon=None,
device_class=DEVICE_CLASS_POWER,
state_class=STATE_CLASS_MEASUREMENT,
@ -227,7 +227,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.realpower.nominal": SensorEntityDescription(
key="ups.realpower.nominal",
name="Nominal Real Power",
unit_of_measurement=POWER_WATT,
native_unit_of_measurement=POWER_WATT,
icon=None,
device_class=DEVICE_CLASS_POWER,
state_class=None,
@ -235,7 +235,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.beeper.status": SensorEntityDescription(
key="ups.beeper.status",
name="Beeper Status",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:information-outline",
device_class=None,
state_class=None,
@ -243,7 +243,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.type": SensorEntityDescription(
key="ups.type",
name="UPS Type",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:information-outline",
device_class=None,
state_class=None,
@ -251,7 +251,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.watchdog.status": SensorEntityDescription(
key="ups.watchdog.status",
name="Watchdog Status",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:information-outline",
device_class=None,
state_class=None,
@ -259,7 +259,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.start.auto": SensorEntityDescription(
key="ups.start.auto",
name="Start on AC",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:information-outline",
device_class=None,
state_class=None,
@ -267,7 +267,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.start.battery": SensorEntityDescription(
key="ups.start.battery",
name="Start on Battery",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:information-outline",
device_class=None,
state_class=None,
@ -275,7 +275,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.start.reboot": SensorEntityDescription(
key="ups.start.reboot",
name="Reboot on Battery",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:information-outline",
device_class=None,
state_class=None,
@ -283,7 +283,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ups.shutdown": SensorEntityDescription(
key="ups.shutdown",
name="Shutdown Ability",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:information-outline",
device_class=None,
state_class=None,
@ -291,7 +291,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"battery.charge": SensorEntityDescription(
key="battery.charge",
name="Battery Charge",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
icon=None,
device_class=DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT,
@ -299,7 +299,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"battery.charge.low": SensorEntityDescription(
key="battery.charge.low",
name="Low Battery Setpoint",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
icon="mdi:gauge",
device_class=None,
state_class=None,
@ -307,7 +307,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"battery.charge.restart": SensorEntityDescription(
key="battery.charge.restart",
name="Minimum Battery to Start",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
icon="mdi:gauge",
device_class=None,
state_class=None,
@ -315,7 +315,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"battery.charge.warning": SensorEntityDescription(
key="battery.charge.warning",
name="Warning Battery Setpoint",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
icon="mdi:gauge",
device_class=None,
state_class=None,
@ -323,7 +323,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"battery.charger.status": SensorEntityDescription(
key="battery.charger.status",
name="Charging Status",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:information-outline",
device_class=None,
state_class=None,
@ -331,7 +331,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"battery.voltage": SensorEntityDescription(
key="battery.voltage",
name="Battery Voltage",
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
icon=None,
device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT,
@ -339,7 +339,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"battery.voltage.nominal": SensorEntityDescription(
key="battery.voltage.nominal",
name="Nominal Battery Voltage",
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
icon=None,
device_class=DEVICE_CLASS_VOLTAGE,
state_class=None,
@ -347,7 +347,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"battery.voltage.low": SensorEntityDescription(
key="battery.voltage.low",
name="Low Battery Voltage",
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
icon=None,
device_class=DEVICE_CLASS_VOLTAGE,
state_class=None,
@ -355,7 +355,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"battery.voltage.high": SensorEntityDescription(
key="battery.voltage.high",
name="High Battery Voltage",
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
icon=None,
device_class=DEVICE_CLASS_VOLTAGE,
state_class=None,
@ -363,7 +363,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"battery.capacity": SensorEntityDescription(
key="battery.capacity",
name="Battery Capacity",
unit_of_measurement="Ah",
native_unit_of_measurement="Ah",
icon="mdi:flash",
device_class=None,
state_class=None,
@ -371,7 +371,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"battery.current": SensorEntityDescription(
key="battery.current",
name="Battery Current",
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
icon="mdi:flash",
device_class=None,
state_class=STATE_CLASS_MEASUREMENT,
@ -379,7 +379,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"battery.current.total": SensorEntityDescription(
key="battery.current.total",
name="Total Battery Current",
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
icon="mdi:flash",
device_class=None,
state_class=None,
@ -387,7 +387,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"battery.temperature": SensorEntityDescription(
key="battery.temperature",
name="Battery Temperature",
unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=TEMP_CELSIUS,
icon=None,
device_class=DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT,
@ -395,7 +395,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"battery.runtime": SensorEntityDescription(
key="battery.runtime",
name="Battery Runtime",
unit_of_measurement=TIME_SECONDS,
native_unit_of_measurement=TIME_SECONDS,
icon="mdi:timer-outline",
device_class=None,
state_class=None,
@ -403,7 +403,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"battery.runtime.low": SensorEntityDescription(
key="battery.runtime.low",
name="Low Battery Runtime",
unit_of_measurement=TIME_SECONDS,
native_unit_of_measurement=TIME_SECONDS,
icon="mdi:timer-outline",
device_class=None,
state_class=None,
@ -411,7 +411,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"battery.runtime.restart": SensorEntityDescription(
key="battery.runtime.restart",
name="Minimum Battery Runtime to Start",
unit_of_measurement=TIME_SECONDS,
native_unit_of_measurement=TIME_SECONDS,
icon="mdi:timer-outline",
device_class=None,
state_class=None,
@ -419,7 +419,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"battery.alarm.threshold": SensorEntityDescription(
key="battery.alarm.threshold",
name="Battery Alarm Threshold",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:information-outline",
device_class=None,
state_class=None,
@ -427,7 +427,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"battery.date": SensorEntityDescription(
key="battery.date",
name="Battery Date",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:calendar",
device_class=None,
state_class=None,
@ -435,7 +435,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"battery.mfr.date": SensorEntityDescription(
key="battery.mfr.date",
name="Battery Manuf. Date",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:calendar",
device_class=None,
state_class=None,
@ -443,7 +443,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"battery.packs": SensorEntityDescription(
key="battery.packs",
name="Number of Batteries",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:information-outline",
device_class=None,
state_class=None,
@ -451,7 +451,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"battery.packs.bad": SensorEntityDescription(
key="battery.packs.bad",
name="Number of Bad Batteries",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:information-outline",
device_class=None,
state_class=None,
@ -459,7 +459,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"battery.type": SensorEntityDescription(
key="battery.type",
name="Battery Chemistry",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:information-outline",
device_class=None,
state_class=None,
@ -467,7 +467,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"input.sensitivity": SensorEntityDescription(
key="input.sensitivity",
name="Input Power Sensitivity",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:information-outline",
device_class=None,
state_class=None,
@ -475,7 +475,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"input.transfer.low": SensorEntityDescription(
key="input.transfer.low",
name="Low Voltage Transfer",
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
icon=None,
device_class=DEVICE_CLASS_VOLTAGE,
state_class=None,
@ -483,7 +483,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"input.transfer.high": SensorEntityDescription(
key="input.transfer.high",
name="High Voltage Transfer",
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
icon=None,
device_class=DEVICE_CLASS_VOLTAGE,
state_class=None,
@ -491,7 +491,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"input.transfer.reason": SensorEntityDescription(
key="input.transfer.reason",
name="Voltage Transfer Reason",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:information-outline",
device_class=None,
state_class=None,
@ -499,7 +499,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"input.voltage": SensorEntityDescription(
key="input.voltage",
name="Input Voltage",
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
icon=None,
device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT,
@ -507,7 +507,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"input.voltage.nominal": SensorEntityDescription(
key="input.voltage.nominal",
name="Nominal Input Voltage",
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
icon=None,
device_class=DEVICE_CLASS_VOLTAGE,
state_class=None,
@ -515,7 +515,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"input.frequency": SensorEntityDescription(
key="input.frequency",
name="Input Line Frequency",
unit_of_measurement=FREQUENCY_HERTZ,
native_unit_of_measurement=FREQUENCY_HERTZ,
icon="mdi:flash",
device_class=None,
state_class=STATE_CLASS_MEASUREMENT,
@ -523,7 +523,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"input.frequency.nominal": SensorEntityDescription(
key="input.frequency.nominal",
name="Nominal Input Line Frequency",
unit_of_measurement=FREQUENCY_HERTZ,
native_unit_of_measurement=FREQUENCY_HERTZ,
icon="mdi:flash",
device_class=None,
state_class=None,
@ -531,7 +531,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"input.frequency.status": SensorEntityDescription(
key="input.frequency.status",
name="Input Frequency Status",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:information-outline",
device_class=None,
state_class=None,
@ -539,7 +539,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"output.current": SensorEntityDescription(
key="output.current",
name="Output Current",
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
icon="mdi:flash",
device_class=None,
state_class=STATE_CLASS_MEASUREMENT,
@ -547,7 +547,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"output.current.nominal": SensorEntityDescription(
key="output.current.nominal",
name="Nominal Output Current",
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
icon="mdi:flash",
device_class=None,
state_class=None,
@ -555,7 +555,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"output.voltage": SensorEntityDescription(
key="output.voltage",
name="Output Voltage",
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
icon=None,
device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT,
@ -563,7 +563,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"output.voltage.nominal": SensorEntityDescription(
key="output.voltage.nominal",
name="Nominal Output Voltage",
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
icon=None,
device_class=DEVICE_CLASS_VOLTAGE,
state_class=None,
@ -571,7 +571,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"output.frequency": SensorEntityDescription(
key="output.frequency",
name="Output Frequency",
unit_of_measurement=FREQUENCY_HERTZ,
native_unit_of_measurement=FREQUENCY_HERTZ,
icon="mdi:flash",
device_class=None,
state_class=STATE_CLASS_MEASUREMENT,
@ -579,7 +579,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"output.frequency.nominal": SensorEntityDescription(
key="output.frequency.nominal",
name="Nominal Output Frequency",
unit_of_measurement=FREQUENCY_HERTZ,
native_unit_of_measurement=FREQUENCY_HERTZ,
icon="mdi:flash",
device_class=None,
state_class=None,
@ -587,7 +587,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ambient.humidity": SensorEntityDescription(
key="ambient.humidity",
name="Ambient Humidity",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
icon=None,
device_class=DEVICE_CLASS_HUMIDITY,
state_class=STATE_CLASS_MEASUREMENT,
@ -595,7 +595,7 @@ SENSOR_TYPES: Final[dict[str, SensorEntityDescription]] = {
"ambient.temperature": SensorEntityDescription(
key="ambient.temperature",
name="Ambient Temperature",
unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=TEMP_CELSIUS,
icon=None,
device_class=DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT,

View File

@ -130,7 +130,7 @@ class NUTSensor(CoordinatorEntity, SensorEntity):
return f"{self._unique_id}_{self.entity_description.key}"
@property
def state(self):
def native_value(self):
"""Return entity state from ups."""
if not self._data.status:
return None

View File

@ -113,7 +113,7 @@ SENSOR_TYPES: tuple[NWSSensorEntityDescription, ...] = (
name="Dew Point",
icon=None,
device_class=DEVICE_CLASS_TEMPERATURE,
unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=TEMP_CELSIUS,
unit_convert=TEMP_CELSIUS,
),
NWSSensorEntityDescription(
@ -121,7 +121,7 @@ SENSOR_TYPES: tuple[NWSSensorEntityDescription, ...] = (
name="Temperature",
icon=None,
device_class=DEVICE_CLASS_TEMPERATURE,
unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=TEMP_CELSIUS,
unit_convert=TEMP_CELSIUS,
),
NWSSensorEntityDescription(
@ -129,7 +129,7 @@ SENSOR_TYPES: tuple[NWSSensorEntityDescription, ...] = (
name="Wind Chill",
icon=None,
device_class=DEVICE_CLASS_TEMPERATURE,
unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=TEMP_CELSIUS,
unit_convert=TEMP_CELSIUS,
),
NWSSensorEntityDescription(
@ -137,7 +137,7 @@ SENSOR_TYPES: tuple[NWSSensorEntityDescription, ...] = (
name="Heat Index",
icon=None,
device_class=DEVICE_CLASS_TEMPERATURE,
unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=TEMP_CELSIUS,
unit_convert=TEMP_CELSIUS,
),
NWSSensorEntityDescription(
@ -145,7 +145,7 @@ SENSOR_TYPES: tuple[NWSSensorEntityDescription, ...] = (
name="Relative Humidity",
icon=None,
device_class=DEVICE_CLASS_HUMIDITY,
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
unit_convert=PERCENTAGE,
),
NWSSensorEntityDescription(
@ -153,7 +153,7 @@ SENSOR_TYPES: tuple[NWSSensorEntityDescription, ...] = (
name="Wind Speed",
icon="mdi:weather-windy",
device_class=None,
unit_of_measurement=SPEED_KILOMETERS_PER_HOUR,
native_unit_of_measurement=SPEED_KILOMETERS_PER_HOUR,
unit_convert=SPEED_MILES_PER_HOUR,
),
NWSSensorEntityDescription(
@ -161,7 +161,7 @@ SENSOR_TYPES: tuple[NWSSensorEntityDescription, ...] = (
name="Wind Gust",
icon="mdi:weather-windy",
device_class=None,
unit_of_measurement=SPEED_KILOMETERS_PER_HOUR,
native_unit_of_measurement=SPEED_KILOMETERS_PER_HOUR,
unit_convert=SPEED_MILES_PER_HOUR,
),
NWSSensorEntityDescription(
@ -169,7 +169,7 @@ SENSOR_TYPES: tuple[NWSSensorEntityDescription, ...] = (
name="Wind Direction",
icon="mdi:compass-rose",
device_class=None,
unit_of_measurement=DEGREE,
native_unit_of_measurement=DEGREE,
unit_convert=DEGREE,
),
NWSSensorEntityDescription(
@ -177,7 +177,7 @@ SENSOR_TYPES: tuple[NWSSensorEntityDescription, ...] = (
name="Barometric Pressure",
icon=None,
device_class=DEVICE_CLASS_PRESSURE,
unit_of_measurement=PRESSURE_PA,
native_unit_of_measurement=PRESSURE_PA,
unit_convert=PRESSURE_INHG,
),
NWSSensorEntityDescription(
@ -185,7 +185,7 @@ SENSOR_TYPES: tuple[NWSSensorEntityDescription, ...] = (
name="Sea Level Pressure",
icon=None,
device_class=DEVICE_CLASS_PRESSURE,
unit_of_measurement=PRESSURE_PA,
native_unit_of_measurement=PRESSURE_PA,
unit_convert=PRESSURE_INHG,
),
NWSSensorEntityDescription(
@ -193,7 +193,7 @@ SENSOR_TYPES: tuple[NWSSensorEntityDescription, ...] = (
name="Visibility",
icon="mdi:eye",
device_class=None,
unit_of_measurement=LENGTH_METERS,
native_unit_of_measurement=LENGTH_METERS,
unit_convert=LENGTH_MILES,
),
)

View File

@ -73,16 +73,16 @@ class NWSSensor(CoordinatorEntity, SensorEntity):
self._attr_name = f"{station} {description.name}"
if not hass.config.units.is_metric:
self._attr_unit_of_measurement = description.unit_convert
self._attr_native_unit_of_measurement = description.unit_convert
@property
def state(self):
def native_value(self):
"""Return the state."""
value = self._nws.observation.get(self.entity_description.key)
if value is None:
return None
# Set alias to unit property -> prevent unnecessary hasattr calls
unit_of_measurement = self.unit_of_measurement
unit_of_measurement = self.native_unit_of_measurement
if unit_of_measurement == SPEED_MILES_PER_HOUR:
return round(convert_distance(value, LENGTH_KILOMETERS, LENGTH_MILES))
if unit_of_measurement == LENGTH_MILES:

View File

@ -103,12 +103,12 @@ class NZBGetSensor(NZBGetEntity, SensorEntity):
return self._unique_id
@property
def unit_of_measurement(self) -> str:
def native_unit_of_measurement(self) -> str:
"""Return the unit that the state of sensor is expressed in."""
return self._unit_of_measurement
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
value = self.coordinator.data["status"].get(self._sensor_type)

View File

@ -73,7 +73,7 @@ class OASATelematicsSensor(SensorEntity):
return DEVICE_CLASS_TIMESTAMP
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._state

View File

@ -85,7 +85,7 @@ class ObihaiServiceSensors(SensorEntity):
return self._name
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._state

View File

@ -107,7 +107,7 @@ class OctoPrintSensor(SensorEntity):
return self._name
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
sensor_unit = self.unit_of_measurement
if sensor_unit in (TEMP_CELSIUS, PERCENTAGE):
@ -118,7 +118,7 @@ class OctoPrintSensor(SensorEntity):
return self._state
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement

View File

@ -48,7 +48,7 @@ class OhmconnectSensor(SensorEntity):
return self._name
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
if self._data.get("active") == "True":
return "Active"

View File

@ -53,7 +53,7 @@ class OmbiSensor(SensorEntity):
return self._icon
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._state

View File

@ -86,7 +86,7 @@ class OmnilogicSensor(OmniLogicEntity, SensorEntity):
return self._device_class
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the right unit of measure."""
return self._unit
@ -95,7 +95,7 @@ class OmniLogicTemperatureSensor(OmnilogicSensor):
"""Define an OmniLogic Temperature (Air/Water) Sensor."""
@property
def state(self):
def native_value(self):
"""Return the state for the temperature sensor."""
sensor_data = self.coordinator.data[self._item_id][self._state_key]
@ -123,7 +123,7 @@ class OmniLogicPumpSpeedSensor(OmnilogicSensor):
"""Define an OmniLogic Pump Speed Sensor."""
@property
def state(self):
def native_value(self):
"""Return the state for the pump speed sensor."""
pump_type = PUMP_TYPES[
@ -158,7 +158,7 @@ class OmniLogicSaltLevelSensor(OmnilogicSensor):
"""Define an OmniLogic Salt Level Sensor."""
@property
def state(self):
def native_value(self):
"""Return the state for the salt level sensor."""
salt_return = self.coordinator.data[self._item_id][self._state_key]
@ -177,7 +177,7 @@ class OmniLogicChlorinatorSensor(OmnilogicSensor):
"""Define an OmniLogic Chlorinator Sensor."""
@property
def state(self):
def native_value(self):
"""Return the state for the chlorinator sensor."""
state = self.coordinator.data[self._item_id][self._state_key]
@ -188,7 +188,7 @@ class OmniLogicPHSensor(OmnilogicSensor):
"""Define an OmniLogic pH Sensor."""
@property
def state(self):
def native_value(self):
"""Return the state for the pH sensor."""
ph_state = self.coordinator.data[self._item_id][self._state_key]
@ -232,7 +232,7 @@ class OmniLogicORPSensor(OmnilogicSensor):
)
@property
def state(self):
def native_value(self):
"""Return the state for the ORP sensor."""
orp_state = int(self.coordinator.data[self._item_id][self._state_key])

View File

@ -28,49 +28,49 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription(
key="temperature",
name="Temperature",
unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=TEMP_CELSIUS,
icon=None,
device_class=DEVICE_CLASS_TEMPERATURE,
),
SensorEntityDescription(
key="orp",
name="Oxydo Reduction Potential",
unit_of_measurement=ELECTRIC_POTENTIAL_MILLIVOLT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_MILLIVOLT,
icon="mdi:pool",
device_class=None,
),
SensorEntityDescription(
key="ph",
name="pH",
unit_of_measurement=None,
native_unit_of_measurement=None,
icon="mdi:pool",
device_class=None,
),
SensorEntityDescription(
key="tds",
name="TDS",
unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
icon="mdi:pool",
device_class=None,
),
SensorEntityDescription(
key="battery",
name="Battery",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
icon=None,
device_class=DEVICE_CLASS_BATTERY,
),
SensorEntityDescription(
key="rssi",
name="RSSI",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
icon=None,
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
),
SensorEntityDescription(
key="salt",
name="Salt",
unit_of_measurement="mg/L",
native_unit_of_measurement="mg/L",
icon="mdi:pool",
device_class=None,
),
@ -164,7 +164,7 @@ class OndiloICO(CoordinatorEntity, SensorEntity):
)
@property
def state(self):
def native_value(self):
"""Last value of the sensor."""
return self._devdata()["value"]

View File

@ -368,7 +368,7 @@ class OneWireSensor(OneWireBaseEntity, SensorEntity):
"""Mixin for sensor specific attributes."""
@property
def unit_of_measurement(self) -> str | None:
def native_unit_of_measurement(self) -> str | None:
"""Return the unit the value is expressed in."""
return self._unit_of_measurement
@ -377,7 +377,7 @@ class OneWireProxySensor(OneWireProxyEntity, OneWireSensor):
"""Implementation of a 1-Wire sensor connected through owserver."""
@property
def state(self) -> StateType:
def native_value(self) -> StateType:
"""Return the state of the entity."""
return self._state
@ -405,7 +405,7 @@ class OneWireDirectSensor(OneWireSensor):
self._owsensor = owsensor
@property
def state(self) -> StateType:
def native_value(self) -> StateType:
"""Return the state of the entity."""
return self._state

View File

@ -44,7 +44,7 @@ class ONVIFSensor(ONVIFBaseEntity, SensorEntity):
super().__init__(device)
@property
def state(self) -> None | str | int | float:
def native_value(self) -> None | str | int | float:
"""Return the state of the entity."""
return self.device.events.get_uid(self.uid).value
@ -59,7 +59,7 @@ class ONVIFSensor(ONVIFBaseEntity, SensorEntity):
return self.device.events.get_uid(self.uid).device_class
@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 self.device.events.get_uid(self.uid).unit_of_measurement

View File

@ -44,7 +44,7 @@ class OpenERZSensor(SensorEntity):
return self._name
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._state

View File

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

View File

@ -73,7 +73,7 @@ class OpenexchangeratesSensor(SensorEntity):
return self._name
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._state

View File

@ -62,12 +62,12 @@ class OpenHardwareMonitorDevice(SensorEntity):
return self._name
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement."""
return self._unit_of_measurement
@property
def state(self):
def native_value(self):
"""Return the state of the device."""
return self.value

View File

@ -107,7 +107,7 @@ class OpenSkySensor(SensorEntity):
return self._name
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._state
@ -178,7 +178,7 @@ class OpenSkySensor(SensorEntity):
return {ATTR_ATTRIBUTION: OPENSKY_ATTRIBUTION}
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement."""
return "flights"

View File

@ -156,12 +156,12 @@ class OpenThermSensor(SensorEntity):
return self._device_class
@property
def state(self):
def native_value(self):
"""Return the state of the device."""
return self._value
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement."""
return self._unit

View File

@ -105,7 +105,7 @@ class OpenUvSensor(OpenUvEntity, SensorEntity):
self._attr_icon = icon
self._attr_name = name
self._attr_unit_of_measurement = unit
self._attr_native_unit_of_measurement = unit
@callback
def update_from_latest_data(self) -> None:
@ -119,22 +119,22 @@ class OpenUvSensor(OpenUvEntity, SensorEntity):
self._attr_available = True
if self._sensor_type == TYPE_CURRENT_OZONE_LEVEL:
self._attr_state = data["ozone"]
self._attr_native_value = data["ozone"]
elif self._sensor_type == TYPE_CURRENT_UV_INDEX:
self._attr_state = data["uv"]
self._attr_native_value = data["uv"]
elif self._sensor_type == TYPE_CURRENT_UV_LEVEL:
if data["uv"] >= 11:
self._attr_state = UV_LEVEL_EXTREME
self._attr_native_value = UV_LEVEL_EXTREME
elif data["uv"] >= 8:
self._attr_state = UV_LEVEL_VHIGH
self._attr_native_value = UV_LEVEL_VHIGH
elif data["uv"] >= 6:
self._attr_state = UV_LEVEL_HIGH
self._attr_native_value = UV_LEVEL_HIGH
elif data["uv"] >= 3:
self._attr_state = UV_LEVEL_MODERATE
self._attr_native_value = UV_LEVEL_MODERATE
else:
self._attr_state = UV_LEVEL_LOW
self._attr_native_value = UV_LEVEL_LOW
elif self._sensor_type == TYPE_MAX_UV_INDEX:
self._attr_state = data["uv_max"]
self._attr_native_value = data["uv_max"]
uv_max_time = parse_datetime(data["uv_max_time"])
if uv_max_time:
self._attr_extra_state_attributes.update(
@ -148,6 +148,6 @@ class OpenUvSensor(OpenUvEntity, SensorEntity):
TYPE_SAFE_EXPOSURE_TIME_5,
TYPE_SAFE_EXPOSURE_TIME_6,
):
self._attr_state = data["safe_exposure_time"][
self._attr_native_value = data["safe_exposure_time"][
EXPOSURE_TYPE_MAP[self._sensor_type]
]

View File

@ -71,7 +71,7 @@ class AbstractOpenWeatherMapSensor(SensorEntity):
return self._device_class
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement

View File

@ -68,7 +68,7 @@ class OpenWeatherMapSensor(AbstractOpenWeatherMapSensor):
self._weather_coordinator = weather_coordinator
@property
def state(self):
def native_value(self):
"""Return the state of the device."""
return self._weather_coordinator.data.get(self._sensor_type, None)
@ -91,7 +91,7 @@ class OpenWeatherMapForecastSensor(AbstractOpenWeatherMapSensor):
self._weather_coordinator = weather_coordinator
@property
def state(self):
def native_value(self):
"""Return the state of the device."""
forecasts = self._weather_coordinator.data.get(ATTR_API_FORECAST)
if forecasts is not None and len(forecasts) > 0:

View File

@ -42,7 +42,7 @@ class CurrentEnergyUsageSensor(SensorEntity):
"""Representation of the sensor."""
_attr_icon = SENSOR_ICON
_attr_unit_of_measurement = ENERGY_KILO_WATT_HOUR
_attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR
def __init__(self, meter):
"""Initialize the sensor."""
@ -61,7 +61,7 @@ class CurrentEnergyUsageSensor(SensorEntity):
return SENSOR_NAME
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._state

View File

@ -63,7 +63,7 @@ class TOTPSensor(SensorEntity):
return self._name
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._state

View File

@ -81,7 +81,7 @@ class OVOEnergySensor(OVOEnergyDeviceEntity, SensorEntity):
super().__init__(coordinator, client, key, name, icon)
@property
def unit_of_measurement(self) -> str | None:
def native_unit_of_measurement(self) -> str | None:
"""Return the unit this state is expressed in."""
return self._unit_of_measurement
@ -103,7 +103,7 @@ class OVOEnergyLastElectricityReading(OVOEnergySensor):
)
@property
def state(self) -> str:
def native_value(self) -> str:
"""Return the state of the sensor."""
usage: OVODailyUsage = self.coordinator.data
if usage is None or not usage.electricity:
@ -139,7 +139,7 @@ class OVOEnergyLastGasReading(OVOEnergySensor):
)
@property
def state(self) -> str:
def native_value(self) -> str:
"""Return the state of the sensor."""
usage: OVODailyUsage = self.coordinator.data
if usage is None or not usage.gas:
@ -176,7 +176,7 @@ class OVOEnergyLastElectricityCost(OVOEnergySensor):
)
@property
def state(self) -> str:
def native_value(self) -> str:
"""Return the state of the sensor."""
usage: OVODailyUsage = self.coordinator.data
if usage is None or not usage.electricity:
@ -213,7 +213,7 @@ class OVOEnergyLastGasCost(OVOEnergySensor):
)
@property
def state(self) -> str:
def native_value(self) -> str:
"""Return the state of the sensor."""
usage: OVODailyUsage = self.coordinator.data
if usage is None or not usage.gas:

View File

@ -106,12 +106,12 @@ class ZWaveStringSensor(ZwaveSensorBase):
"""Representation of a Z-Wave sensor."""
@property
def state(self):
def native_value(self):
"""Return state of the sensor."""
return self.values.primary.value
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return unit of measurement the value is expressed in."""
return self.values.primary.units
@ -125,12 +125,12 @@ class ZWaveNumericSensor(ZwaveSensorBase):
"""Representation of a Z-Wave sensor."""
@property
def state(self):
def native_value(self):
"""Return state of the sensor."""
return round(self.values.primary.value, 2)
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return unit of measurement the value is expressed in."""
if self.values.primary.units == "C":
return TEMP_CELSIUS
@ -144,7 +144,7 @@ class ZWaveListSensor(ZwaveSensorBase):
"""Representation of a Z-Wave list sensor."""
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
# We use the id as value for backwards compatibility
return self.values.primary.value["Selected_id"]

View File

@ -41,55 +41,55 @@ SENSOR_TYPES: tuple[PiHoleSensorEntityDescription, ...] = (
PiHoleSensorEntityDescription(
key="ads_blocked_today",
name="Ads Blocked Today",
unit_of_measurement="ads",
native_unit_of_measurement="ads",
icon="mdi:close-octagon-outline",
),
PiHoleSensorEntityDescription(
key="ads_percentage_today",
name="Ads Percentage Blocked Today",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
icon="mdi:close-octagon-outline",
),
PiHoleSensorEntityDescription(
key="clients_ever_seen",
name="Seen Clients",
unit_of_measurement="clients",
native_unit_of_measurement="clients",
icon="mdi:account-outline",
),
PiHoleSensorEntityDescription(
key="dns_queries_today",
name="DNS Queries Today",
unit_of_measurement="queries",
native_unit_of_measurement="queries",
icon="mdi:comment-question-outline",
),
PiHoleSensorEntityDescription(
key="domains_being_blocked",
name="Domains Blocked",
unit_of_measurement="domains",
native_unit_of_measurement="domains",
icon="mdi:block-helper",
),
PiHoleSensorEntityDescription(
key="queries_cached",
name="DNS Queries Cached",
unit_of_measurement="queries",
native_unit_of_measurement="queries",
icon="mdi:comment-question-outline",
),
PiHoleSensorEntityDescription(
key="queries_forwarded",
name="DNS Queries Forwarded",
unit_of_measurement="queries",
native_unit_of_measurement="queries",
icon="mdi:comment-question-outline",
),
PiHoleSensorEntityDescription(
key="unique_clients",
name="DNS Unique Clients",
unit_of_measurement="clients",
native_unit_of_measurement="clients",
icon="mdi:account-outline",
),
PiHoleSensorEntityDescription(
key="unique_domains",
name="DNS Unique Domains",
unit_of_measurement="domains",
native_unit_of_measurement="domains",
icon="mdi:domain",
),
)

View File

@ -63,7 +63,7 @@ class PiHoleSensor(PiHoleEntity, SensorEntity):
self._attr_unique_id = f"{self._server_unique_id}/{description.name}"
@property
def state(self) -> Any:
def native_value(self) -> Any:
"""Return the state of the device."""
try:
return round(self.api.data[self.entity_description.key], 2)

View File

@ -3,6 +3,7 @@ from __future__ import annotations
from typing import Any
from homeassistant.components.sensor import SensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_ATTRIBUTION
from homeassistant.core import HomeAssistant
@ -30,7 +31,7 @@ async def async_setup_entry(
return True
class PicnicSensor(CoordinatorEntity):
class PicnicSensor(SensorEntity, CoordinatorEntity):
"""The CoordinatorEntity subclass representing Picnic sensors."""
def __init__(
@ -49,7 +50,7 @@ class PicnicSensor(CoordinatorEntity):
self._service_unique_id = config_entry.unique_id
@property
def unit_of_measurement(self) -> str | None:
def native_unit_of_measurement(self) -> str | None:
"""Return the unit this state is expressed in."""
return self.properties.get("unit")
@ -64,7 +65,7 @@ class PicnicSensor(CoordinatorEntity):
return self._to_capitalized_name(self.sensor_type)
@property
def state(self) -> StateType:
def native_value(self) -> StateType:
"""Return the state of the entity."""
data_set = (
self.coordinator.data.get(self.properties["data_type"], {})

View File

@ -63,12 +63,12 @@ class PilightSensor(SensorEntity):
return self._name
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit this state is expressed in."""
return self._unit_of_measurement
@property
def state(self):
def native_value(self):
"""Return the state of the entity."""
return self._state

View File

@ -75,11 +75,11 @@ class PlaatoSensor(PlaatoEntity, SensorEntity):
return None
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._sensor_data.sensors.get(self._sensor_type)
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement."""
return self._sensor_data.get_unit_of_measurement(self._sensor_type)

View File

@ -62,7 +62,7 @@ class PlexSensor(SensorEntity):
self._attr_name = NAME_FORMAT.format(plex_server.friendly_name)
self._attr_should_poll = False
self._attr_unique_id = f"sensor-{plex_server.machine_identifier}"
self._attr_unit_of_measurement = "Watching"
self._attr_native_unit_of_measurement = "Watching"
self._server = plex_server
self.async_refresh_sensor = Debouncer(
@ -87,7 +87,7 @@ class PlexSensor(SensorEntity):
async def _async_refresh_sensor(self):
"""Set instance object and trigger an entity state update."""
_LOGGER.debug("Refreshing sensor [%s]", self.unique_id)
self._attr_state = len(self._server.sensor_attributes)
self._attr_native_value = len(self._server.sensor_attributes)
self.async_write_ha_state()
@property
@ -128,7 +128,7 @@ class PlexLibrarySectionSensor(SensorEntity):
self._attr_name = f"{self.server_name} Library - {plex_library_section.title}"
self._attr_should_poll = False
self._attr_unique_id = f"library-{self.server_id}-{plex_library_section.uuid}"
self._attr_unit_of_measurement = "Items"
self._attr_native_unit_of_measurement = "Items"
async def async_added_to_hass(self):
"""Run when about to be added to hass."""
@ -164,7 +164,7 @@ class PlexLibrarySectionSensor(SensorEntity):
self.library_type, self.library_type
)
self._attr_state = self.library_section.totalViewSize(
self._attr_native_value = self.library_section.totalViewSize(
libtype=primary_libtype, includeCollections=False
)
for libtype in LIBRARY_ATTRIBUTE_TYPES.get(self.library_type, []):

View File

@ -272,12 +272,12 @@ class SmileSensor(SmileGateway, SensorEntity):
return self._icon
@property
def state(self):
def native_value(self):
"""Return the state of this entity."""
return self._state
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement

View File

@ -50,7 +50,7 @@ class PocketCastsSensor(SensorEntity):
return SENSOR_NAME
@property
def state(self):
def native_value(self):
"""Return the sensor state."""
return self._state

View File

@ -70,13 +70,13 @@ class MinutPointSensor(MinutPointEntity, SensorEntity):
return self._device_prop[0]
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
if self.value is None:
return None
return round(self.value, self._device_prop[1])
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement."""
return self._device_prop[2]

View File

@ -89,7 +89,7 @@ class PoolSenseSensor(PoolSenseEntity, SensorEntity):
return f"PoolSense {SENSORS[self.info_type]['name']}"
@property
def state(self):
def native_value(self):
"""State of the sensor."""
return self.coordinator.data[self.info_type]
@ -104,7 +104,7 @@ class PoolSenseSensor(PoolSenseEntity, SensorEntity):
return SENSORS[self.info_type]["icon"]
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return unit of measurement."""
return SENSORS[self.info_type]["unit"]

View File

@ -87,7 +87,7 @@ class PowerWallChargeSensor(PowerWallEntity, SensorEntity):
"""Representation of an Powerwall charge sensor."""
_attr_name = "Powerwall Charge"
_attr_unit_of_measurement = PERCENTAGE
_attr_native_unit_of_measurement = PERCENTAGE
_attr_device_class = DEVICE_CLASS_BATTERY
@property
@ -96,7 +96,7 @@ class PowerWallChargeSensor(PowerWallEntity, SensorEntity):
return f"{self.base_unique_id}_charge"
@property
def state(self):
def native_value(self):
"""Get the current value in percentage."""
return round(self.coordinator.data[POWERWALL_API_CHARGE])
@ -105,7 +105,7 @@ class PowerWallEnergySensor(PowerWallEntity, SensorEntity):
"""Representation of an Powerwall Energy sensor."""
_attr_state_class = STATE_CLASS_MEASUREMENT
_attr_unit_of_measurement = POWER_KILO_WATT
_attr_native_unit_of_measurement = POWER_KILO_WATT
_attr_device_class = DEVICE_CLASS_POWER
def __init__(
@ -128,7 +128,7 @@ class PowerWallEnergySensor(PowerWallEntity, SensorEntity):
)
@property
def state(self):
def native_value(self):
"""Get the current value in kW."""
return (
self.coordinator.data[POWERWALL_API_METERS]

View File

@ -79,7 +79,7 @@ class PushBulletNotificationSensor(SensorEntity):
return f"Pushbullet {self._element}"
@property
def state(self):
def native_value(self):
"""Return the current state of the sensor."""
return self._state

View File

@ -79,7 +79,7 @@ class PvoutputSensor(SensorEntity, RestoreEntity):
_attr_state_class = STATE_CLASS_MEASUREMENT
_attr_device_class = DEVICE_CLASS_ENERGY
_attr_unit_of_measurement = ENERGY_WATT_HOUR
_attr_native_unit_of_measurement = ENERGY_WATT_HOUR
_old_state: int | None = None
@ -104,7 +104,7 @@ class PvoutputSensor(SensorEntity, RestoreEntity):
)
@property
def state(self):
def native_value(self):
"""Return the state of the device."""
if self.pvcoutput is not None:
return self.pvcoutput.energy_generation

View File

@ -106,7 +106,7 @@ class ElecPriceSensor(RestoreEntity, SensorEntity):
return self._name
@property
def state(self) -> float:
def native_value(self) -> float:
"""Return the state of the sensor."""
return self._pvpc_data.state

View File

@ -93,12 +93,12 @@ class PyLoadSensor(SensorEntity):
return self._name
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._state
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement

View File

@ -90,7 +90,7 @@ class QBittorrentSensor(SensorEntity):
return f"{self.client_name} {self._name}"
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._state
@ -100,7 +100,7 @@ class QBittorrentSensor(SensorEntity):
return self._available
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement

View File

@ -243,7 +243,7 @@ class QNAPSensor(SensorEntity):
return self.var_icon
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self.var_units
@ -256,7 +256,7 @@ class QNAPCPUSensor(QNAPSensor):
"""A QNAP sensor that monitors CPU stats."""
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
if self.var_id == "cpu_temp":
return self._api.data["system_stats"]["cpu"]["temp_c"]
@ -268,7 +268,7 @@ class QNAPMemorySensor(QNAPSensor):
"""A QNAP sensor that monitors memory stats."""
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
free = float(self._api.data["system_stats"]["memory"]["free"]) / 1024
if self.var_id == "memory_free":
@ -296,7 +296,7 @@ class QNAPNetworkSensor(QNAPSensor):
"""A QNAP sensor that monitors network stats."""
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
if self.var_id == "network_link_status":
nic = self._api.data["system_stats"]["nics"][self.monitor_device]
@ -329,7 +329,7 @@ class QNAPSystemSensor(QNAPSensor):
"""A QNAP sensor that monitors overall system health."""
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
if self.var_id == "status":
return self._api.data["system_health"]
@ -358,7 +358,7 @@ class QNAPDriveSensor(QNAPSensor):
"""A QNAP sensor that monitors HDD/SSD drive stats."""
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
data = self._api.data["smart_drive_health"][self.monitor_device]
@ -392,7 +392,7 @@ class QNAPVolumeSensor(QNAPSensor):
"""A QNAP sensor that monitors storage volume stats."""
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
data = self._api.data["volumes"][self.monitor_device]

View File

@ -57,7 +57,7 @@ class QSSensor(QSEntity, SensorEntity):
self.async_write_ha_state()
@property
def state(self):
def native_value(self):
"""Return the value of the sensor."""
return str(self._val)
@ -67,6 +67,6 @@ class QSSensor(QSEntity, SensorEntity):
return f"qs{self.qsid}:{self.channel}"
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self.unit