From 103e21c278300d328b1b5bbc78d9d6fd77908b6c Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Thu, 12 Aug 2021 13:26:17 +0200 Subject: [PATCH] Move temperature conversions to sensor base class (5/8) (#54475) --- homeassistant/components/nam/const.py | 38 ++--- homeassistant/components/nam/sensor.py | 4 +- homeassistant/components/neato/sensor.py | 4 +- .../nederlandse_spoorwegen/sensor.py | 2 +- .../components/nest/legacy/sensor.py | 8 +- homeassistant/components/nest/sensor_sdm.py | 8 +- homeassistant/components/netatmo/sensor.py | 54 +++---- homeassistant/components/netdata/sensor.py | 6 +- .../components/netgear_lte/sensor.py | 10 +- .../components/neurio_energy/sensor.py | 4 +- homeassistant/components/nexia/sensor.py | 8 +- homeassistant/components/nextbus/sensor.py | 2 +- homeassistant/components/nextcloud/sensor.py | 2 +- homeassistant/components/nightscout/sensor.py | 4 +- .../components/nissan_leaf/sensor.py | 8 +- homeassistant/components/nmbs/sensor.py | 6 +- homeassistant/components/noaa_tides/sensor.py | 2 +- homeassistant/components/notion/sensor.py | 4 +- .../components/nsw_fuel_station/sensor.py | 4 +- homeassistant/components/numato/sensor.py | 4 +- homeassistant/components/nut/const.py | 138 +++++++++--------- homeassistant/components/nut/sensor.py | 2 +- homeassistant/components/nws/const.py | 22 +-- homeassistant/components/nws/sensor.py | 6 +- homeassistant/components/nzbget/sensor.py | 4 +- .../components/oasa_telematics/sensor.py | 2 +- homeassistant/components/obihai/sensor.py | 2 +- homeassistant/components/octoprint/sensor.py | 4 +- homeassistant/components/ohmconnect/sensor.py | 2 +- homeassistant/components/ombi/sensor.py | 2 +- homeassistant/components/omnilogic/sensor.py | 14 +- homeassistant/components/ondilo_ico/sensor.py | 16 +- homeassistant/components/onewire/sensor.py | 6 +- homeassistant/components/onvif/sensor.py | 4 +- homeassistant/components/openerz/sensor.py | 2 +- homeassistant/components/openevse/sensor.py | 4 +- .../components/openexchangerates/sensor.py | 2 +- .../components/openhardwaremonitor/sensor.py | 4 +- homeassistant/components/opensky/sensor.py | 4 +- .../components/opentherm_gw/sensor.py | 4 +- homeassistant/components/openuv/sensor.py | 20 +-- .../openweathermap/abstract_owm_sensor.py | 2 +- .../components/openweathermap/sensor.py | 4 +- homeassistant/components/oru/sensor.py | 4 +- homeassistant/components/otp/sensor.py | 2 +- homeassistant/components/ovo_energy/sensor.py | 10 +- homeassistant/components/ozw/sensor.py | 10 +- homeassistant/components/pi_hole/const.py | 18 +-- homeassistant/components/pi_hole/sensor.py | 2 +- homeassistant/components/picnic/sensor.py | 7 +- homeassistant/components/pilight/sensor.py | 4 +- homeassistant/components/plaato/sensor.py | 4 +- homeassistant/components/plex/sensor.py | 8 +- homeassistant/components/plugwise/sensor.py | 4 +- .../components/pocketcasts/sensor.py | 2 +- homeassistant/components/point/sensor.py | 4 +- homeassistant/components/poolsense/sensor.py | 4 +- homeassistant/components/powerwall/sensor.py | 8 +- homeassistant/components/pushbullet/sensor.py | 2 +- homeassistant/components/pvoutput/sensor.py | 4 +- .../components/pvpc_hourly_pricing/sensor.py | 2 +- homeassistant/components/pyload/sensor.py | 4 +- .../components/qbittorrent/sensor.py | 4 +- homeassistant/components/qnap/sensor.py | 14 +- homeassistant/components/qwikswitch/sensor.py | 4 +- 65 files changed, 289 insertions(+), 288 deletions(-) diff --git a/homeassistant/components/nam/const.py b/homeassistant/components/nam/const.py index 85472deba06..a9d044f2c1d 100644 --- a/homeassistant/components/nam/const.py +++ b/homeassistant/components/nam/const.py @@ -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, diff --git a/homeassistant/components/nam/sensor.py b/homeassistant/components/nam/sensor.py index 298f88d5c29..c5c9c9f2e77 100644 --- a/homeassistant/components/nam/sensor.py +++ b/homeassistant/components/nam/sensor.py @@ -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 ( diff --git a/homeassistant/components/neato/sensor.py b/homeassistant/components/neato/sensor.py index 1cf10112b92..2d54e89bb04 100644 --- a/homeassistant/components/neato/sensor.py +++ b/homeassistant/components/neato/sensor.py @@ -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 diff --git a/homeassistant/components/nederlandse_spoorwegen/sensor.py b/homeassistant/components/nederlandse_spoorwegen/sensor.py index de8a85f44fd..8cbe7b1f803 100644 --- a/homeassistant/components/nederlandse_spoorwegen/sensor.py +++ b/homeassistant/components/nederlandse_spoorwegen/sensor.py @@ -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 diff --git a/homeassistant/components/nest/legacy/sensor.py b/homeassistant/components/nest/legacy/sensor.py index 0939e925b43..f2c6670bf8b 100644 --- a/homeassistant/components/nest/legacy/sensor.py +++ b/homeassistant/components/nest/legacy/sensor.py @@ -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 diff --git a/homeassistant/components/nest/sensor_sdm.py b/homeassistant/components/nest/sensor_sdm.py index 42614af8c40..0034acff3af 100644 --- a/homeassistant/components/nest/sensor_sdm.py +++ b/homeassistant/components/nest/sensor_sdm.py @@ -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 diff --git a/homeassistant/components/netatmo/sensor.py b/homeassistant/components/netatmo/sensor.py index 0c55b459847..a1f7b2ac079 100644 --- a/homeassistant/components/netatmo/sensor.py +++ b/homeassistant/components/netatmo/sensor.py @@ -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() diff --git a/homeassistant/components/netdata/sensor.py b/homeassistant/components/netdata/sensor.py index 21e4cd1b005..d1fa87a6e5d 100644 --- a/homeassistant/components/netdata/sensor.py +++ b/homeassistant/components/netdata/sensor.py @@ -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 diff --git a/homeassistant/components/netgear_lte/sensor.py b/homeassistant/components/netgear_lte/sensor.py index c8f07301e98..0996ad3d315 100644 --- a/homeassistant/components/netgear_lte/sensor.py +++ b/homeassistant/components/netgear_lte/sensor.py @@ -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) diff --git a/homeassistant/components/neurio_energy/sensor.py b/homeassistant/components/neurio_energy/sensor.py index d74d6338c8b..37113dde8b7 100644 --- a/homeassistant/components/neurio_energy/sensor.py +++ b/homeassistant/components/neurio_energy/sensor.py @@ -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 diff --git a/homeassistant/components/nexia/sensor.py b/homeassistant/components/nexia/sensor.py index a14931e41ee..6e44b8c9883 100644 --- a/homeassistant/components/nexia/sensor.py +++ b/homeassistant/components/nexia/sensor.py @@ -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 diff --git a/homeassistant/components/nextbus/sensor.py b/homeassistant/components/nextbus/sensor.py index fb03bcd25b5..f9df0d60412 100644 --- a/homeassistant/components/nextbus/sensor.py +++ b/homeassistant/components/nextbus/sensor.py @@ -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 diff --git a/homeassistant/components/nextcloud/sensor.py b/homeassistant/components/nextcloud/sensor.py index 5cd02f124e9..6a2d106bb10 100644 --- a/homeassistant/components/nextcloud/sensor.py +++ b/homeassistant/components/nextcloud/sensor.py @@ -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 diff --git a/homeassistant/components/nightscout/sensor.py b/homeassistant/components/nightscout/sensor.py index 183755298d6..1b37fa8da7c 100644 --- a/homeassistant/components/nightscout/sensor.py +++ b/homeassistant/components/nightscout/sensor.py @@ -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 diff --git a/homeassistant/components/nissan_leaf/sensor.py b/homeassistant/components/nissan_leaf/sensor.py index 936d607a84e..4074cd47f50 100644 --- a/homeassistant/components/nissan_leaf/sensor.py +++ b/homeassistant/components/nissan_leaf/sensor.py @@ -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 diff --git a/homeassistant/components/nmbs/sensor.py b/homeassistant/components/nmbs/sensor.py index 26f7dbd2c8a..72e51837bb8 100644 --- a/homeassistant/components/nmbs/sensor.py +++ b/homeassistant/components/nmbs/sensor.py @@ -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 diff --git a/homeassistant/components/noaa_tides/sensor.py b/homeassistant/components/noaa_tides/sensor.py index e637e953173..5dbee551bb7 100644 --- a/homeassistant/components/noaa_tides/sensor.py +++ b/homeassistant/components/noaa_tides/sensor.py @@ -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 diff --git a/homeassistant/components/notion/sensor.py b/homeassistant/components/notion/sensor.py index 48b9a25f783..cf6c394dbda 100644 --- a/homeassistant/components/notion/sensor.py +++ b/homeassistant/components/notion/sensor.py @@ -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", diff --git a/homeassistant/components/nsw_fuel_station/sensor.py b/homeassistant/components/nsw_fuel_station/sensor.py index 52536e69027..139728a3405 100644 --- a/homeassistant/components/nsw_fuel_station/sensor.py +++ b/homeassistant/components/nsw_fuel_station/sensor.py @@ -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}" diff --git a/homeassistant/components/numato/sensor.py b/homeassistant/components/numato/sensor.py index 19372de5258..fcf719c979e 100644 --- a/homeassistant/components/numato/sensor.py +++ b/homeassistant/components/numato/sensor.py @@ -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 diff --git a/homeassistant/components/nut/const.py b/homeassistant/components/nut/const.py index b48121eeaf8..5bdd9049456 100644 --- a/homeassistant/components/nut/const.py +++ b/homeassistant/components/nut/const.py @@ -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, diff --git a/homeassistant/components/nut/sensor.py b/homeassistant/components/nut/sensor.py index 456778c3ca5..971c194c1c9 100644 --- a/homeassistant/components/nut/sensor.py +++ b/homeassistant/components/nut/sensor.py @@ -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 diff --git a/homeassistant/components/nws/const.py b/homeassistant/components/nws/const.py index 6e08ef408d3..32018bc40bb 100644 --- a/homeassistant/components/nws/const.py +++ b/homeassistant/components/nws/const.py @@ -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, ), ) diff --git a/homeassistant/components/nws/sensor.py b/homeassistant/components/nws/sensor.py index 409856831a2..85b60ffd475 100644 --- a/homeassistant/components/nws/sensor.py +++ b/homeassistant/components/nws/sensor.py @@ -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: diff --git a/homeassistant/components/nzbget/sensor.py b/homeassistant/components/nzbget/sensor.py index 97bced9e9c2..325438908a7 100644 --- a/homeassistant/components/nzbget/sensor.py +++ b/homeassistant/components/nzbget/sensor.py @@ -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) diff --git a/homeassistant/components/oasa_telematics/sensor.py b/homeassistant/components/oasa_telematics/sensor.py index 71af8dacba2..4c9b583a36b 100644 --- a/homeassistant/components/oasa_telematics/sensor.py +++ b/homeassistant/components/oasa_telematics/sensor.py @@ -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 diff --git a/homeassistant/components/obihai/sensor.py b/homeassistant/components/obihai/sensor.py index 639b9eb332f..7ba28ee0741 100644 --- a/homeassistant/components/obihai/sensor.py +++ b/homeassistant/components/obihai/sensor.py @@ -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 diff --git a/homeassistant/components/octoprint/sensor.py b/homeassistant/components/octoprint/sensor.py index 16f6efce004..5b2b0af494c 100644 --- a/homeassistant/components/octoprint/sensor.py +++ b/homeassistant/components/octoprint/sensor.py @@ -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 diff --git a/homeassistant/components/ohmconnect/sensor.py b/homeassistant/components/ohmconnect/sensor.py index b53c35e17b5..0638b32d105 100644 --- a/homeassistant/components/ohmconnect/sensor.py +++ b/homeassistant/components/ohmconnect/sensor.py @@ -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" diff --git a/homeassistant/components/ombi/sensor.py b/homeassistant/components/ombi/sensor.py index c91cf429c94..50bb121dc4b 100644 --- a/homeassistant/components/ombi/sensor.py +++ b/homeassistant/components/ombi/sensor.py @@ -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 diff --git a/homeassistant/components/omnilogic/sensor.py b/homeassistant/components/omnilogic/sensor.py index 1f8de082868..f0382c01342 100644 --- a/homeassistant/components/omnilogic/sensor.py +++ b/homeassistant/components/omnilogic/sensor.py @@ -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]) diff --git a/homeassistant/components/ondilo_ico/sensor.py b/homeassistant/components/ondilo_ico/sensor.py index 7449524d9e5..693d685f77c 100644 --- a/homeassistant/components/ondilo_ico/sensor.py +++ b/homeassistant/components/ondilo_ico/sensor.py @@ -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"] diff --git a/homeassistant/components/onewire/sensor.py b/homeassistant/components/onewire/sensor.py index 024d540c10a..215ba6c569b 100644 --- a/homeassistant/components/onewire/sensor.py +++ b/homeassistant/components/onewire/sensor.py @@ -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 diff --git a/homeassistant/components/onvif/sensor.py b/homeassistant/components/onvif/sensor.py index 1c5766e3969..5c31644ba19 100644 --- a/homeassistant/components/onvif/sensor.py +++ b/homeassistant/components/onvif/sensor.py @@ -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 diff --git a/homeassistant/components/openerz/sensor.py b/homeassistant/components/openerz/sensor.py index 33305b677de..8a3c2c0460d 100644 --- a/homeassistant/components/openerz/sensor.py +++ b/homeassistant/components/openerz/sensor.py @@ -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 diff --git a/homeassistant/components/openevse/sensor.py b/homeassistant/components/openevse/sensor.py index 29eeceb232c..a1920e145bb 100644 --- a/homeassistant/components/openevse/sensor.py +++ b/homeassistant/components/openevse/sensor.py @@ -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 diff --git a/homeassistant/components/openexchangerates/sensor.py b/homeassistant/components/openexchangerates/sensor.py index 8474cdab131..803123a88c3 100644 --- a/homeassistant/components/openexchangerates/sensor.py +++ b/homeassistant/components/openexchangerates/sensor.py @@ -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 diff --git a/homeassistant/components/openhardwaremonitor/sensor.py b/homeassistant/components/openhardwaremonitor/sensor.py index 8f43c1e5e9b..280acab5d0e 100644 --- a/homeassistant/components/openhardwaremonitor/sensor.py +++ b/homeassistant/components/openhardwaremonitor/sensor.py @@ -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 diff --git a/homeassistant/components/opensky/sensor.py b/homeassistant/components/opensky/sensor.py index 122388b85b7..0502d6c6573 100644 --- a/homeassistant/components/opensky/sensor.py +++ b/homeassistant/components/opensky/sensor.py @@ -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" diff --git a/homeassistant/components/opentherm_gw/sensor.py b/homeassistant/components/opentherm_gw/sensor.py index 1d9904ea59f..28f139f188f 100644 --- a/homeassistant/components/opentherm_gw/sensor.py +++ b/homeassistant/components/opentherm_gw/sensor.py @@ -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 diff --git a/homeassistant/components/openuv/sensor.py b/homeassistant/components/openuv/sensor.py index 386527ebc3e..e115f9294a5 100644 --- a/homeassistant/components/openuv/sensor.py +++ b/homeassistant/components/openuv/sensor.py @@ -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] ] diff --git a/homeassistant/components/openweathermap/abstract_owm_sensor.py b/homeassistant/components/openweathermap/abstract_owm_sensor.py index ea12123b707..3c66ca50f3c 100644 --- a/homeassistant/components/openweathermap/abstract_owm_sensor.py +++ b/homeassistant/components/openweathermap/abstract_owm_sensor.py @@ -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 diff --git a/homeassistant/components/openweathermap/sensor.py b/homeassistant/components/openweathermap/sensor.py index 39c50c3b941..3586f958a6a 100644 --- a/homeassistant/components/openweathermap/sensor.py +++ b/homeassistant/components/openweathermap/sensor.py @@ -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: diff --git a/homeassistant/components/oru/sensor.py b/homeassistant/components/oru/sensor.py index c17873aefea..dc2b7216534 100644 --- a/homeassistant/components/oru/sensor.py +++ b/homeassistant/components/oru/sensor.py @@ -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 diff --git a/homeassistant/components/otp/sensor.py b/homeassistant/components/otp/sensor.py index 7aee9d99208..45bedb6b499 100644 --- a/homeassistant/components/otp/sensor.py +++ b/homeassistant/components/otp/sensor.py @@ -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 diff --git a/homeassistant/components/ovo_energy/sensor.py b/homeassistant/components/ovo_energy/sensor.py index f678caf02b0..91290238dce 100644 --- a/homeassistant/components/ovo_energy/sensor.py +++ b/homeassistant/components/ovo_energy/sensor.py @@ -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: diff --git a/homeassistant/components/ozw/sensor.py b/homeassistant/components/ozw/sensor.py index 0ff08a87d16..97b7b01d4d4 100644 --- a/homeassistant/components/ozw/sensor.py +++ b/homeassistant/components/ozw/sensor.py @@ -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"] diff --git a/homeassistant/components/pi_hole/const.py b/homeassistant/components/pi_hole/const.py index 52c638864a5..f1ec1c6efd6 100644 --- a/homeassistant/components/pi_hole/const.py +++ b/homeassistant/components/pi_hole/const.py @@ -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", ), ) diff --git a/homeassistant/components/pi_hole/sensor.py b/homeassistant/components/pi_hole/sensor.py index 14aed86a479..0e231868647 100644 --- a/homeassistant/components/pi_hole/sensor.py +++ b/homeassistant/components/pi_hole/sensor.py @@ -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) diff --git a/homeassistant/components/picnic/sensor.py b/homeassistant/components/picnic/sensor.py index 3a4d3582f9c..57f24180c03 100644 --- a/homeassistant/components/picnic/sensor.py +++ b/homeassistant/components/picnic/sensor.py @@ -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"], {}) diff --git a/homeassistant/components/pilight/sensor.py b/homeassistant/components/pilight/sensor.py index 97458acd5fc..bc8135c5932 100644 --- a/homeassistant/components/pilight/sensor.py +++ b/homeassistant/components/pilight/sensor.py @@ -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 diff --git a/homeassistant/components/plaato/sensor.py b/homeassistant/components/plaato/sensor.py index 9af16a1cacd..e3e37d4291e 100644 --- a/homeassistant/components/plaato/sensor.py +++ b/homeassistant/components/plaato/sensor.py @@ -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) diff --git a/homeassistant/components/plex/sensor.py b/homeassistant/components/plex/sensor.py index 8ca72e8fb83..0969967e673 100644 --- a/homeassistant/components/plex/sensor.py +++ b/homeassistant/components/plex/sensor.py @@ -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, []): diff --git a/homeassistant/components/plugwise/sensor.py b/homeassistant/components/plugwise/sensor.py index 4152f9fdabd..854c2e6676c 100644 --- a/homeassistant/components/plugwise/sensor.py +++ b/homeassistant/components/plugwise/sensor.py @@ -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 diff --git a/homeassistant/components/pocketcasts/sensor.py b/homeassistant/components/pocketcasts/sensor.py index 55ae4a524fc..f745bd562bd 100644 --- a/homeassistant/components/pocketcasts/sensor.py +++ b/homeassistant/components/pocketcasts/sensor.py @@ -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 diff --git a/homeassistant/components/point/sensor.py b/homeassistant/components/point/sensor.py index dc34e1f9367..87981d7b29e 100644 --- a/homeassistant/components/point/sensor.py +++ b/homeassistant/components/point/sensor.py @@ -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] diff --git a/homeassistant/components/poolsense/sensor.py b/homeassistant/components/poolsense/sensor.py index dd03111e85e..e9aeaca20f5 100644 --- a/homeassistant/components/poolsense/sensor.py +++ b/homeassistant/components/poolsense/sensor.py @@ -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"] diff --git a/homeassistant/components/powerwall/sensor.py b/homeassistant/components/powerwall/sensor.py index b2281c515ae..96542dc3929 100644 --- a/homeassistant/components/powerwall/sensor.py +++ b/homeassistant/components/powerwall/sensor.py @@ -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] diff --git a/homeassistant/components/pushbullet/sensor.py b/homeassistant/components/pushbullet/sensor.py index 4f8ec6a1700..3585c198a51 100644 --- a/homeassistant/components/pushbullet/sensor.py +++ b/homeassistant/components/pushbullet/sensor.py @@ -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 diff --git a/homeassistant/components/pvoutput/sensor.py b/homeassistant/components/pvoutput/sensor.py index 305615e4b2c..722aea8e868 100644 --- a/homeassistant/components/pvoutput/sensor.py +++ b/homeassistant/components/pvoutput/sensor.py @@ -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 diff --git a/homeassistant/components/pvpc_hourly_pricing/sensor.py b/homeassistant/components/pvpc_hourly_pricing/sensor.py index 75881f93f0a..157327fbd19 100644 --- a/homeassistant/components/pvpc_hourly_pricing/sensor.py +++ b/homeassistant/components/pvpc_hourly_pricing/sensor.py @@ -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 diff --git a/homeassistant/components/pyload/sensor.py b/homeassistant/components/pyload/sensor.py index c439d5181be..f568b41776f 100644 --- a/homeassistant/components/pyload/sensor.py +++ b/homeassistant/components/pyload/sensor.py @@ -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 diff --git a/homeassistant/components/qbittorrent/sensor.py b/homeassistant/components/qbittorrent/sensor.py index 251407099b1..5f57cd19cfe 100644 --- a/homeassistant/components/qbittorrent/sensor.py +++ b/homeassistant/components/qbittorrent/sensor.py @@ -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 diff --git a/homeassistant/components/qnap/sensor.py b/homeassistant/components/qnap/sensor.py index c175d89f60e..333ce46599a 100644 --- a/homeassistant/components/qnap/sensor.py +++ b/homeassistant/components/qnap/sensor.py @@ -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] diff --git a/homeassistant/components/qwikswitch/sensor.py b/homeassistant/components/qwikswitch/sensor.py index f6d0ce7ec28..5de7bc0dccf 100644 --- a/homeassistant/components/qwikswitch/sensor.py +++ b/homeassistant/components/qwikswitch/sensor.py @@ -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