diff --git a/homeassistant/components/radarr/sensor.py b/homeassistant/components/radarr/sensor.py index 407f491f63a..02e898c8e0f 100644 --- a/homeassistant/components/radarr/sensor.py +++ b/homeassistant/components/radarr/sensor.py @@ -127,7 +127,7 @@ class RadarrSensor(SensorEntity): return "{} {}".format("Radarr", self._name) @property - def state(self): + def native_value(self): """Return sensor state.""" return self._state @@ -137,7 +137,7 @@ class RadarrSensor(SensorEntity): return self._available @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit of the sensor.""" return self._unit diff --git a/homeassistant/components/rainbird/sensor.py b/homeassistant/components/rainbird/sensor.py index 2158bc5cf97..0f6ad41b4e3 100644 --- a/homeassistant/components/rainbird/sensor.py +++ b/homeassistant/components/rainbird/sensor.py @@ -45,6 +45,6 @@ class RainBirdSensor(SensorEntity): """Get the latest data and updates the states.""" _LOGGER.debug("Updating sensor: %s", self.name) if self.entity_description.key == SENSOR_TYPE_RAINSENSOR: - self._attr_state = self._controller.get_rain_sensor_state() + self._attr_native_value = self._controller.get_rain_sensor_state() elif self.entity_description.key == SENSOR_TYPE_RAINDELAY: - self._attr_state = self._controller.get_rain_delay() + self._attr_native_value = self._controller.get_rain_delay() diff --git a/homeassistant/components/raincloud/sensor.py b/homeassistant/components/raincloud/sensor.py index ee8f68734ad..c550e43285b 100644 --- a/homeassistant/components/raincloud/sensor.py +++ b/homeassistant/components/raincloud/sensor.py @@ -48,12 +48,12 @@ class RainCloudSensor(RainCloudEntity, SensorEntity): """A sensor implementation for raincloud device.""" @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 units of measurement.""" return UNIT_OF_MEASUREMENT_MAP.get(self._sensor_type) diff --git a/homeassistant/components/rainforest_eagle/sensor.py b/homeassistant/components/rainforest_eagle/sensor.py index 53e94d2070e..64eb243c15d 100644 --- a/homeassistant/components/rainforest_eagle/sensor.py +++ b/homeassistant/components/rainforest_eagle/sensor.py @@ -131,7 +131,7 @@ class EagleSensor(SensorEntity): self._type = sensor_type sensor_info = SENSORS[sensor_type] self._attr_name = sensor_info.name - self._attr_unit_of_measurement = sensor_info.unit_of_measurement + self._attr_native_unit_of_measurement = sensor_info.unit_of_measurement self._attr_device_class = sensor_info.device_class self._attr_state_class = sensor_info.state_class self._attr_last_reset = sensor_info.last_reset @@ -139,7 +139,7 @@ class EagleSensor(SensorEntity): def update(self): """Get the energy information from the Rainforest Eagle.""" self.eagle_data.update() - self._attr_state = self.eagle_data.get_state(self._type) + self._attr_native_value = self.eagle_data.get_state(self._type) class EagleData: diff --git a/homeassistant/components/rainmachine/sensor.py b/homeassistant/components/rainmachine/sensor.py index 808c6a06bc2..2316b27acbf 100644 --- a/homeassistant/components/rainmachine/sensor.py +++ b/homeassistant/components/rainmachine/sensor.py @@ -134,7 +134,7 @@ class RainMachineSensor(RainMachineEntity, SensorEntity): self._attr_entity_registry_enabled_default = enabled_by_default self._attr_icon = icon self._attr_name = name - self._attr_unit_of_measurement = unit + self._attr_native_unit_of_measurement = unit class ProvisionSettingsSensor(RainMachineSensor): @@ -144,7 +144,7 @@ class ProvisionSettingsSensor(RainMachineSensor): def update_from_latest_data(self) -> None: """Update the state.""" if self._entity_type == TYPE_FLOW_SENSOR_CLICK_M3: - self._attr_state = self.coordinator.data["system"].get( + self._attr_native_value = self.coordinator.data["system"].get( "flowSensorClicksPerCubicMeter" ) elif self._entity_type == TYPE_FLOW_SENSOR_CONSUMED_LITERS: @@ -154,15 +154,15 @@ class ProvisionSettingsSensor(RainMachineSensor): ) if clicks and clicks_per_m3: - self._attr_state = (clicks * 1000) / clicks_per_m3 + self._attr_native_value = (clicks * 1000) / clicks_per_m3 else: - self._attr_state = None + self._attr_native_value = None elif self._entity_type == TYPE_FLOW_SENSOR_START_INDEX: - self._attr_state = self.coordinator.data["system"].get( + self._attr_native_value = self.coordinator.data["system"].get( "flowSensorStartIndex" ) elif self._entity_type == TYPE_FLOW_SENSOR_WATERING_CLICKS: - self._attr_state = self.coordinator.data["system"].get( + self._attr_native_value = self.coordinator.data["system"].get( "flowSensorWateringClicks" ) @@ -174,4 +174,4 @@ class UniversalRestrictionsSensor(RainMachineSensor): def update_from_latest_data(self) -> None: """Update the state.""" if self._entity_type == TYPE_FREEZE_TEMP: - self._attr_state = self.coordinator.data["freezeProtectTemp"] + self._attr_native_value = self.coordinator.data["freezeProtectTemp"] diff --git a/homeassistant/components/random/sensor.py b/homeassistant/components/random/sensor.py index 6465b828be1..91a34639de1 100644 --- a/homeassistant/components/random/sensor.py +++ b/homeassistant/components/random/sensor.py @@ -58,7 +58,7 @@ class RandomSensor(SensorEntity): return self._name @property - def state(self): + def native_value(self): """Return the state of the device.""" return self._state @@ -68,7 +68,7 @@ class RandomSensor(SensorEntity): return ICON @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 diff --git a/homeassistant/components/recollect_waste/sensor.py b/homeassistant/components/recollect_waste/sensor.py index beb7c182351..304eaafb85f 100644 --- a/homeassistant/components/recollect_waste/sensor.py +++ b/homeassistant/components/recollect_waste/sensor.py @@ -127,4 +127,4 @@ class ReCollectWasteSensor(CoordinatorEntity, SensorEntity): ATTR_NEXT_PICKUP_DATE: as_utc(next_pickup_event.date).isoformat(), } ) - self._attr_state = as_utc(pickup_event.date).isoformat() + self._attr_native_value = as_utc(pickup_event.date).isoformat() diff --git a/homeassistant/components/reddit/sensor.py b/homeassistant/components/reddit/sensor.py index 7472ad42301..2e1ec5dc18a 100644 --- a/homeassistant/components/reddit/sensor.py +++ b/homeassistant/components/reddit/sensor.py @@ -99,7 +99,7 @@ class RedditSensor(SensorEntity): return f"reddit_{self._subreddit}" @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return len(self._subreddit_data) diff --git a/homeassistant/components/rejseplanen/sensor.py b/homeassistant/components/rejseplanen/sensor.py index 78b713c286c..99e2f90c879 100644 --- a/homeassistant/components/rejseplanen/sensor.py +++ b/homeassistant/components/rejseplanen/sensor.py @@ -105,7 +105,7 @@ class RejseplanenTransportSensor(SensorEntity): return self._name @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return self._state @@ -131,7 +131,7 @@ class RejseplanenTransportSensor(SensorEntity): return attributes @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit this state is expressed in.""" return TIME_MINUTES diff --git a/homeassistant/components/repetier/sensor.py b/homeassistant/components/repetier/sensor.py index 46818095647..04cff82bcf3 100644 --- a/homeassistant/components/repetier/sensor.py +++ b/homeassistant/components/repetier/sensor.py @@ -77,7 +77,7 @@ class RepetierSensor(SensorEntity): return self._name @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit of measurement of this entity, if any.""" return SENSOR_TYPES[self._sensor_type][1] @@ -92,7 +92,7 @@ class RepetierSensor(SensorEntity): return False @property - def state(self): + def native_value(self): """Return sensor state.""" return self._state @@ -134,7 +134,7 @@ class RepetierTempSensor(RepetierSensor): """Represent a Repetier temp sensor.""" @property - def state(self): + def native_value(self): """Return sensor state.""" if self._state is None: return None @@ -156,7 +156,7 @@ class RepetierJobSensor(RepetierSensor): """Represent a Repetier job sensor.""" @property - def state(self): + def native_value(self): """Return sensor state.""" if self._state is None: return None diff --git a/homeassistant/components/rest/sensor.py b/homeassistant/components/rest/sensor.py index 7727b5f09ab..f0355014986 100644 --- a/homeassistant/components/rest/sensor.py +++ b/homeassistant/components/rest/sensor.py @@ -115,12 +115,12 @@ class RestSensor(RestEntity, SensorEntity): self._json_attrs_path = json_attrs_path @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 @property - def state(self): + def native_value(self): """Return the state of the device.""" return self._state diff --git a/homeassistant/components/rflink/sensor.py b/homeassistant/components/rflink/sensor.py index 497c9b8cee6..6b0c9efe157 100644 --- a/homeassistant/components/rflink/sensor.py +++ b/homeassistant/components/rflink/sensor.py @@ -152,12 +152,12 @@ class RflinkSensor(RflinkDevice, SensorEntity): self.handle_event_callback(self._initial_event) @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return measurement unit.""" return self._unit_of_measurement @property - def state(self): + def native_value(self): """Return value.""" return self._state diff --git a/homeassistant/components/rfxtrx/sensor.py b/homeassistant/components/rfxtrx/sensor.py index 8b9d5e5c389..49a8bbb974c 100644 --- a/homeassistant/components/rfxtrx/sensor.py +++ b/homeassistant/components/rfxtrx/sensor.py @@ -78,92 +78,92 @@ SENSOR_TYPES = ( key="Barameter", device_class=DEVICE_CLASS_PRESSURE, state_class=STATE_CLASS_MEASUREMENT, - unit_of_measurement=PRESSURE_HPA, + native_unit_of_measurement=PRESSURE_HPA, ), RfxtrxSensorEntityDescription( key="Battery numeric", device_class=DEVICE_CLASS_BATTERY, state_class=STATE_CLASS_MEASUREMENT, - unit_of_measurement=PERCENTAGE, + native_unit_of_measurement=PERCENTAGE, convert=_battery_convert, ), RfxtrxSensorEntityDescription( key="Current", device_class=DEVICE_CLASS_CURRENT, state_class=STATE_CLASS_MEASUREMENT, - unit_of_measurement=ELECTRIC_CURRENT_AMPERE, + native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE, ), RfxtrxSensorEntityDescription( key="Current Ch. 1", device_class=DEVICE_CLASS_CURRENT, state_class=STATE_CLASS_MEASUREMENT, - unit_of_measurement=ELECTRIC_CURRENT_AMPERE, + native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE, ), RfxtrxSensorEntityDescription( key="Current Ch. 2", device_class=DEVICE_CLASS_CURRENT, state_class=STATE_CLASS_MEASUREMENT, - unit_of_measurement=ELECTRIC_CURRENT_AMPERE, + native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE, ), RfxtrxSensorEntityDescription( key="Current Ch. 3", device_class=DEVICE_CLASS_CURRENT, state_class=STATE_CLASS_MEASUREMENT, - unit_of_measurement=ELECTRIC_CURRENT_AMPERE, + native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE, ), RfxtrxSensorEntityDescription( key="Energy usage", device_class=DEVICE_CLASS_POWER, state_class=STATE_CLASS_MEASUREMENT, - unit_of_measurement=POWER_WATT, + native_unit_of_measurement=POWER_WATT, ), RfxtrxSensorEntityDescription( key="Humidity", device_class=DEVICE_CLASS_HUMIDITY, state_class=STATE_CLASS_MEASUREMENT, - unit_of_measurement=PERCENTAGE, + native_unit_of_measurement=PERCENTAGE, ), RfxtrxSensorEntityDescription( key="Rssi numeric", device_class=DEVICE_CLASS_SIGNAL_STRENGTH, state_class=STATE_CLASS_MEASUREMENT, - unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT, + native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT, convert=_rssi_convert, ), RfxtrxSensorEntityDescription( key="Temperature", device_class=DEVICE_CLASS_TEMPERATURE, state_class=STATE_CLASS_MEASUREMENT, - unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=TEMP_CELSIUS, ), RfxtrxSensorEntityDescription( key="Temperature2", device_class=DEVICE_CLASS_TEMPERATURE, state_class=STATE_CLASS_MEASUREMENT, - unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=TEMP_CELSIUS, ), RfxtrxSensorEntityDescription( key="Total usage", device_class=DEVICE_CLASS_ENERGY, state_class=STATE_CLASS_MEASUREMENT, last_reset=dt.utc_from_timestamp(0), - unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, ), RfxtrxSensorEntityDescription( key="Voltage", device_class=DEVICE_CLASS_VOLTAGE, state_class=STATE_CLASS_MEASUREMENT, - unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, + native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, ), RfxtrxSensorEntityDescription( key="Wind direction", state_class=STATE_CLASS_MEASUREMENT, - unit_of_measurement=DEGREE, + native_unit_of_measurement=DEGREE, ), RfxtrxSensorEntityDescription( key="Rain rate", state_class=STATE_CLASS_MEASUREMENT, - unit_of_measurement=PRECIPITATION_MILLIMETERS_PER_HOUR, + native_unit_of_measurement=PRECIPITATION_MILLIMETERS_PER_HOUR, ), RfxtrxSensorEntityDescription( key="Sound", @@ -175,34 +175,34 @@ SENSOR_TYPES = ( key="Count", state_class=STATE_CLASS_MEASUREMENT, last_reset=dt.utc_from_timestamp(0), - unit_of_measurement="count", + native_unit_of_measurement="count", ), RfxtrxSensorEntityDescription( key="Counter value", state_class=STATE_CLASS_MEASUREMENT, last_reset=dt.utc_from_timestamp(0), - unit_of_measurement="count", + native_unit_of_measurement="count", ), RfxtrxSensorEntityDescription( key="Chill", device_class=DEVICE_CLASS_TEMPERATURE, state_class=STATE_CLASS_MEASUREMENT, - unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=TEMP_CELSIUS, ), RfxtrxSensorEntityDescription( key="Wind average speed", state_class=STATE_CLASS_MEASUREMENT, - unit_of_measurement=SPEED_METERS_PER_SECOND, + native_unit_of_measurement=SPEED_METERS_PER_SECOND, ), RfxtrxSensorEntityDescription( key="Wind gust", state_class=STATE_CLASS_MEASUREMENT, - unit_of_measurement=SPEED_METERS_PER_SECOND, + native_unit_of_measurement=SPEED_METERS_PER_SECOND, ), RfxtrxSensorEntityDescription( key="Rain total", state_class=STATE_CLASS_MEASUREMENT, - unit_of_measurement=LENGTH_MILLIMETERS, + native_unit_of_measurement=LENGTH_MILLIMETERS, ), RfxtrxSensorEntityDescription( key="Forecast", @@ -216,7 +216,7 @@ SENSOR_TYPES = ( RfxtrxSensorEntityDescription( key="UV", state_class=STATE_CLASS_MEASUREMENT, - unit_of_measurement=UV_INDEX, + native_unit_of_measurement=UV_INDEX, ), ) @@ -313,7 +313,7 @@ class RfxtrxSensor(RfxtrxEntity, SensorEntity): self._apply_event(get_rfx_object(event)) @property - def state(self): + def native_value(self): """Return the state of the sensor.""" if not self._event: return None diff --git a/homeassistant/components/ring/sensor.py b/homeassistant/components/ring/sensor.py index 97fb8ec9d21..192ba03c010 100644 --- a/homeassistant/components/ring/sensor.py +++ b/homeassistant/components/ring/sensor.py @@ -56,7 +56,7 @@ class RingSensor(RingEntityMixin, SensorEntity): return self._name @property - def state(self): + def native_value(self): """Return the state of the sensor.""" if self._sensor_type == "volume": return self._device.volume @@ -84,7 +84,7 @@ class RingSensor(RingEntityMixin, SensorEntity): return self._icon @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the units of measurement.""" return SENSOR_TYPES.get(self._sensor_type)[2] @@ -120,7 +120,7 @@ class HealthDataRingSensor(RingSensor): return False @property - def state(self): + def native_value(self): """Return the state of the sensor.""" if self._sensor_type == "wifi_signal_category": return self._device.wifi_signal_category @@ -172,7 +172,7 @@ class HistoryRingSensor(RingSensor): self.async_write_ha_state() @property - def state(self): + def native_value(self): """Return the state of the sensor.""" if self._latest_event is None: return None diff --git a/homeassistant/components/ripple/sensor.py b/homeassistant/components/ripple/sensor.py index f36e2c58ec8..2746f5789cd 100644 --- a/homeassistant/components/ripple/sensor.py +++ b/homeassistant/components/ripple/sensor.py @@ -46,12 +46,12 @@ class RippleSensor(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 this sensor expresses itself in.""" return self._unit_of_measurement diff --git a/homeassistant/components/risco/sensor.py b/homeassistant/components/risco/sensor.py index b39655949b2..0068e8c0f04 100644 --- a/homeassistant/components/risco/sensor.py +++ b/homeassistant/components/risco/sensor.py @@ -87,7 +87,7 @@ class RiscoSensor(CoordinatorEntity, SensorEntity): self.async_write_ha_state() @property - def state(self): + def native_value(self): """Value of sensor.""" if self._event is None: return None diff --git a/homeassistant/components/rituals_perfume_genie/sensor.py b/homeassistant/components/rituals_perfume_genie/sensor.py index 7c957722384..c4b330d1ccf 100644 --- a/homeassistant/components/rituals_perfume_genie/sensor.py +++ b/homeassistant/components/rituals_perfume_genie/sensor.py @@ -59,7 +59,7 @@ class DiffuserPerfumeSensor(DiffuserEntity): return "mdi:tag-remove" @property - def state(self) -> str: + def native_value(self) -> str: """Return the state of the perfume sensor.""" return self._diffuser.perfume @@ -81,7 +81,7 @@ class DiffuserFillSensor(DiffuserEntity): return "mdi:beaker-question" @property - def state(self) -> str: + def native_value(self) -> str: """Return the state of the fill sensor.""" return self._diffuser.fill @@ -90,7 +90,7 @@ class DiffuserBatterySensor(DiffuserEntity): """Representation of a diffuser battery sensor.""" _attr_device_class = DEVICE_CLASS_BATTERY - _attr_unit_of_measurement = PERCENTAGE + _attr_native_unit_of_measurement = PERCENTAGE def __init__( self, diffuser: Diffuser, coordinator: RitualsDataUpdateCoordinator @@ -99,7 +99,7 @@ class DiffuserBatterySensor(DiffuserEntity): super().__init__(diffuser, coordinator, BATTERY_SUFFIX) @property - def state(self) -> int: + def native_value(self) -> int: """Return the state of the battery sensor.""" return self._diffuser.battery_percentage @@ -108,7 +108,7 @@ class DiffuserWifiSensor(DiffuserEntity): """Representation of a diffuser wifi sensor.""" _attr_device_class = DEVICE_CLASS_SIGNAL_STRENGTH - _attr_unit_of_measurement = PERCENTAGE + _attr_native_unit_of_measurement = PERCENTAGE def __init__( self, diffuser: Diffuser, coordinator: RitualsDataUpdateCoordinator @@ -117,6 +117,6 @@ class DiffuserWifiSensor(DiffuserEntity): super().__init__(diffuser, coordinator, WIFI_SUFFIX) @property - def state(self) -> int: + def native_value(self) -> int: """Return the state of the wifi sensor.""" return self._diffuser.wifi_percentage diff --git a/homeassistant/components/rmvtransport/sensor.py b/homeassistant/components/rmvtransport/sensor.py index 9e4e7f3d588..bf2eab2d7b7 100644 --- a/homeassistant/components/rmvtransport/sensor.py +++ b/homeassistant/components/rmvtransport/sensor.py @@ -145,7 +145,7 @@ class RMVDepartureSensor(SensorEntity): return self._state is not None @property - def state(self): + def native_value(self): """Return the next departure time.""" return self._state @@ -171,7 +171,7 @@ class RMVDepartureSensor(SensorEntity): return self._icon @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit this state is expressed in.""" return TIME_MINUTES diff --git a/homeassistant/components/roomba/sensor.py b/homeassistant/components/roomba/sensor.py index 4a99d9f71af..bc20b4397e2 100644 --- a/homeassistant/components/roomba/sensor.py +++ b/homeassistant/components/roomba/sensor.py @@ -36,7 +36,7 @@ class RoombaBattery(IRobotEntity, SensorEntity): return DEVICE_CLASS_BATTERY @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit_of_measurement of the device.""" return PERCENTAGE @@ -50,6 +50,6 @@ class RoombaBattery(IRobotEntity, SensorEntity): ) @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return self._battery_level diff --git a/homeassistant/components/rova/sensor.py b/homeassistant/components/rova/sensor.py index 35d8c0ae2c0..54e2c315a4e 100644 --- a/homeassistant/components/rova/sensor.py +++ b/homeassistant/components/rova/sensor.py @@ -116,7 +116,7 @@ class RovaSensor(SensorEntity): self.data_service.update() pickup_date = self.data_service.data.get(self.entity_description.key) if pickup_date is not None: - self._attr_state = pickup_date.isoformat() + self._attr_native_value = pickup_date.isoformat() class RovaData: diff --git a/homeassistant/components/rtorrent/sensor.py b/homeassistant/components/rtorrent/sensor.py index c750c7aa83c..5379cb2ce2e 100644 --- a/homeassistant/components/rtorrent/sensor.py +++ b/homeassistant/components/rtorrent/sensor.py @@ -94,7 +94,7 @@ class RTorrentSensor(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 @@ -104,7 +104,7 @@ class RTorrentSensor(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/sabnzbd/sensor.py b/homeassistant/components/sabnzbd/sensor.py index c0930f2c114..ffe57e608bf 100644 --- a/homeassistant/components/sabnzbd/sensor.py +++ b/homeassistant/components/sabnzbd/sensor.py @@ -45,7 +45,7 @@ class SabnzbdSensor(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 @@ -55,7 +55,7 @@ class SabnzbdSensor(SensorEntity): return False @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/saj/sensor.py b/homeassistant/components/saj/sensor.py index 1b46632051e..795823b9e9f 100644 --- a/homeassistant/components/saj/sensor.py +++ b/homeassistant/components/saj/sensor.py @@ -191,12 +191,12 @@ class SAJsensor(SensorEntity): return f"saj_{self._sensor.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 SAJ_UNIT_MAPPINGS[self._sensor.unit] diff --git a/homeassistant/components/scrape/sensor.py b/homeassistant/components/scrape/sensor.py index 921ab29f714..1f5b543f9ee 100644 --- a/homeassistant/components/scrape/sensor.py +++ b/homeassistant/components/scrape/sensor.py @@ -108,12 +108,12 @@ class ScrapeSensor(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 @property - def state(self): + def native_value(self): """Return the state of the device.""" return self._state diff --git a/homeassistant/components/screenlogic/sensor.py b/homeassistant/components/screenlogic/sensor.py index 1ad18298655..c8e4f84caf0 100644 --- a/homeassistant/components/screenlogic/sensor.py +++ b/homeassistant/components/screenlogic/sensor.py @@ -114,7 +114,7 @@ class ScreenLogicSensor(ScreenlogicEntity, SensorEntity): return f"{self.gateway_name} {self.sensor['name']}" @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit of measurement.""" return self.sensor.get("unit") @@ -125,7 +125,7 @@ class ScreenLogicSensor(ScreenlogicEntity, SensorEntity): return SL_DEVICE_TYPE_TO_HA_DEVICE_CLASS.get(device_type) @property - def state(self): + def native_value(self): """State of the sensor.""" value = self.sensor["value"] return (value - 1) if "supply" in self._data_key else value @@ -160,7 +160,7 @@ class ScreenLogicChemistrySensor(ScreenLogicSensor): self._key = key @property - def state(self): + def native_value(self): """State of the sensor.""" value = self.sensor["value"] if "dosing_state" in self._key: diff --git a/homeassistant/components/season/sensor.py b/homeassistant/components/season/sensor.py index 165920dd8e5..80fb71f594b 100644 --- a/homeassistant/components/season/sensor.py +++ b/homeassistant/components/season/sensor.py @@ -126,7 +126,7 @@ class Season(SensorEntity): return self._name @property - def state(self): + def native_value(self): """Return the current season.""" return self.season diff --git a/homeassistant/components/sense/sensor.py b/homeassistant/components/sense/sensor.py index 5a352969c3b..69cae55ff31 100644 --- a/homeassistant/components/sense/sensor.py +++ b/homeassistant/components/sense/sensor.py @@ -125,7 +125,7 @@ class SenseActiveSensor(SensorEntity): """Implementation of a Sense energy sensor.""" _attr_icon = ICON - _attr_unit_of_measurement = POWER_WATT + _attr_native_unit_of_measurement = POWER_WATT _attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION} _attr_should_poll = False _attr_available = False @@ -168,9 +168,9 @@ class SenseActiveSensor(SensorEntity): if self._is_production else self._data.active_power ) - if self._attr_available and self._attr_state == new_state: + if self._attr_available and self._attr_native_value == new_state: return - self._attr_state = new_state + self._attr_native_value = new_state self._attr_available = True self.async_write_ha_state() @@ -178,7 +178,7 @@ class SenseActiveSensor(SensorEntity): class SenseVoltageSensor(SensorEntity): """Implementation of a Sense energy voltage sensor.""" - _attr_unit_of_measurement = ELECTRIC_POTENTIAL_VOLT + _attr_native_unit_of_measurement = ELECTRIC_POTENTIAL_VOLT _attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION} _attr_icon = ICON _attr_should_poll = False @@ -212,10 +212,10 @@ class SenseVoltageSensor(SensorEntity): def _async_update_from_data(self): """Update the sensor from the data. Must not do I/O.""" new_state = round(self._data.active_voltage[self._voltage_index], 1) - if self._attr_available and self._attr_state == new_state: + if self._attr_available and self._attr_native_value == new_state: return self._attr_available = True - self._attr_state = new_state + self._attr_native_value = new_state self.async_write_ha_state() @@ -224,7 +224,7 @@ class SenseTrendsSensor(SensorEntity): _attr_device_class = DEVICE_CLASS_ENERGY _attr_state_class = STATE_CLASS_MEASUREMENT - _attr_unit_of_measurement = ENERGY_KILO_WATT_HOUR + _attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR _attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION} _attr_icon = ICON _attr_should_poll = False @@ -249,7 +249,7 @@ class SenseTrendsSensor(SensorEntity): self._had_any_update = False @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return round(self._data.get_trend(self._sensor_type, self._is_production), 1) @@ -288,7 +288,7 @@ class SenseEnergyDevice(SensorEntity): _attr_available = False _attr_state_class = STATE_CLASS_MEASUREMENT - _attr_unit_of_measurement = POWER_WATT + _attr_native_unit_of_measurement = POWER_WATT _attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION} _attr_device_class = DEVICE_CLASS_POWER _attr_should_poll = False @@ -320,8 +320,8 @@ class SenseEnergyDevice(SensorEntity): new_state = 0 else: new_state = int(device_data["w"]) - if self._attr_available and self._attr_state == new_state: + if self._attr_available and self._attr_native_value == new_state: return - self._attr_state = new_state + self._attr_native_value = new_state self._attr_available = True self.async_write_ha_state() diff --git a/homeassistant/components/sensehat/sensor.py b/homeassistant/components/sensehat/sensor.py index 379301b0fa7..9274f133441 100644 --- a/homeassistant/components/sensehat/sensor.py +++ b/homeassistant/components/sensehat/sensor.py @@ -86,12 +86,12 @@ class SenseHatSensor(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/serial/sensor.py b/homeassistant/components/serial/sensor.py index 1e73ae9ac83..cbdba50b6b6 100644 --- a/homeassistant/components/serial/sensor.py +++ b/homeassistant/components/serial/sensor.py @@ -245,6 +245,6 @@ class SerialSensor(SensorEntity): return self._attributes @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return self._state diff --git a/homeassistant/components/serial_pm/sensor.py b/homeassistant/components/serial_pm/sensor.py index fd017661de2..9332f268308 100644 --- a/homeassistant/components/serial_pm/sensor.py +++ b/homeassistant/components/serial_pm/sensor.py @@ -71,12 +71,12 @@ class ParticulateMatterSensor(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 CONCENTRATION_MICROGRAMS_PER_CUBIC_METER diff --git a/homeassistant/components/seventeentrack/sensor.py b/homeassistant/components/seventeentrack/sensor.py index ab0f0779656..44720db2fcb 100644 --- a/homeassistant/components/seventeentrack/sensor.py +++ b/homeassistant/components/seventeentrack/sensor.py @@ -125,7 +125,7 @@ class SeventeenTrackSummarySensor(SensorEntity): return f"Seventeentrack Packages {self._status}" @property - def state(self): + def native_value(self): """Return the state.""" return self._state @@ -135,7 +135,7 @@ class SeventeenTrackSummarySensor(SensorEntity): return f"summary_{self._data.account_id}_{slugify(self._status)}" @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit the value is expressed in.""" return "packages" @@ -211,7 +211,7 @@ class SeventeenTrackPackageSensor(SensorEntity): return f"Seventeentrack Package: {name}" @property - def state(self): + def native_value(self): """Return the state.""" return self._state diff --git a/homeassistant/components/shelly/sensor.py b/homeassistant/components/shelly/sensor.py index 07e4f4a4fe3..e3af10571d5 100644 --- a/homeassistant/components/shelly/sensor.py +++ b/homeassistant/components/shelly/sensor.py @@ -280,7 +280,7 @@ class ShellySensor(ShellyBlockAttributeEntity, SensorEntity): ).replace(second=0, microsecond=0) @property - def state(self) -> StateType: + def native_value(self) -> StateType: """Return value of sensor.""" if ( self.description.last_reset == LAST_RESET_UPTIME @@ -302,7 +302,7 @@ class ShellySensor(ShellyBlockAttributeEntity, SensorEntity): return self.description.state_class @property - def unit_of_measurement(self) -> str | None: + def native_unit_of_measurement(self) -> str | None: """Return unit of sensor.""" return cast(str, self._unit) @@ -311,7 +311,7 @@ class ShellyRestSensor(ShellyRestAttributeEntity, SensorEntity): """Represent a shelly REST sensor.""" @property - def state(self) -> StateType: + def native_value(self) -> StateType: """Return value of sensor.""" return self.attribute_value @@ -321,7 +321,7 @@ class ShellyRestSensor(ShellyRestAttributeEntity, SensorEntity): return self.description.state_class @property - def unit_of_measurement(self) -> str | None: + def native_unit_of_measurement(self) -> str | None: """Return unit of sensor.""" return self.description.unit @@ -330,7 +330,7 @@ class ShellySleepingSensor(ShellySleepingBlockAttributeEntity, SensorEntity): """Represent a shelly sleeping sensor.""" @property - def state(self) -> StateType: + def native_value(self) -> StateType: """Return value of sensor.""" if self.block is not None: return self.attribute_value @@ -343,6 +343,6 @@ class ShellySleepingSensor(ShellySleepingBlockAttributeEntity, SensorEntity): return self.description.state_class @property - def unit_of_measurement(self) -> str | None: + def native_unit_of_measurement(self) -> str | None: """Return unit of sensor.""" return cast(str, self._unit) diff --git a/homeassistant/components/shodan/sensor.py b/homeassistant/components/shodan/sensor.py index fa0fc2d3906..1423a3b9327 100644 --- a/homeassistant/components/shodan/sensor.py +++ b/homeassistant/components/shodan/sensor.py @@ -62,12 +62,12 @@ class ShodanSensor(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/sht31/sensor.py b/homeassistant/components/sht31/sensor.py index a894623db47..1b1e1427e51 100644 --- a/homeassistant/components/sht31/sensor.py +++ b/homeassistant/components/sht31/sensor.py @@ -108,7 +108,7 @@ class SHTSensor(SensorEntity): return self._name @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return self._state @@ -123,7 +123,7 @@ class SHTSensorTemperature(SHTSensor): _attr_device_class = DEVICE_CLASS_TEMPERATURE @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit of measurement.""" return self.hass.config.units.temperature_unit @@ -141,7 +141,7 @@ class SHTSensorHumidity(SHTSensor): """Representation of a humidity sensor.""" @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit of measurement.""" return PERCENTAGE diff --git a/homeassistant/components/sigfox/sensor.py b/homeassistant/components/sigfox/sensor.py index 75c2a4f0f63..41fb3469293 100644 --- a/homeassistant/components/sigfox/sensor.py +++ b/homeassistant/components/sigfox/sensor.py @@ -149,7 +149,7 @@ class SigfoxDevice(SensorEntity): return self._name @property - def state(self): + def native_value(self): """Return the payload of the last message.""" return self._state diff --git a/homeassistant/components/simplisafe/sensor.py b/homeassistant/components/simplisafe/sensor.py index 149319cd5bd..c3f8d7c3ab0 100644 --- a/homeassistant/components/simplisafe/sensor.py +++ b/homeassistant/components/simplisafe/sensor.py @@ -34,9 +34,9 @@ class SimplisafeFreezeSensor(SimpliSafeBaseSensor, SensorEntity): """Define a SimpliSafe freeze sensor entity.""" _attr_device_class = DEVICE_CLASS_TEMPERATURE - _attr_unit_of_measurement = TEMP_FAHRENHEIT + _attr_native_unit_of_measurement = TEMP_FAHRENHEIT @callback def async_update_from_rest_api(self) -> None: """Update the entity with the provided REST API data.""" - self._attr_state = self._sensor.temperature + self._attr_native_value = self._sensor.temperature diff --git a/homeassistant/components/simulated/sensor.py b/homeassistant/components/simulated/sensor.py index 3fe7aedfbb0..819f9c7147c 100644 --- a/homeassistant/components/simulated/sensor.py +++ b/homeassistant/components/simulated/sensor.py @@ -121,7 +121,7 @@ class SimulatedSensor(SensorEntity): return self._name @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return self._state @@ -131,7 +131,7 @@ class SimulatedSensor(SensorEntity): return ICON @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit this state is expressed in.""" return self._unit diff --git a/homeassistant/components/skybeacon/sensor.py b/homeassistant/components/skybeacon/sensor.py index 5b6eae96a7e..a72e1372ca0 100644 --- a/homeassistant/components/skybeacon/sensor.py +++ b/homeassistant/components/skybeacon/sensor.py @@ -65,7 +65,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): class SkybeaconHumid(SensorEntity): """Representation of a Skybeacon humidity sensor.""" - _attr_unit_of_measurement = PERCENTAGE + _attr_native_unit_of_measurement = PERCENTAGE def __init__(self, name, mon): """Initialize a sensor.""" @@ -78,7 +78,7 @@ class SkybeaconHumid(SensorEntity): return self._name @property - def state(self): + def native_value(self): """Return the state of the device.""" return self.mon.data["humid"] @@ -92,7 +92,7 @@ class SkybeaconTemp(SensorEntity): """Representation of a Skybeacon temperature sensor.""" _attr_device_class = DEVICE_CLASS_TEMPERATURE - _attr_unit_of_measurement = TEMP_CELSIUS + _attr_native_unit_of_measurement = TEMP_CELSIUS def __init__(self, name, mon): """Initialize a sensor.""" @@ -105,7 +105,7 @@ class SkybeaconTemp(SensorEntity): return self._name @property - def state(self): + def native_value(self): """Return the state of the device.""" return self.mon.data["temp"] diff --git a/homeassistant/components/skybell/sensor.py b/homeassistant/components/skybell/sensor.py index cee864911b4..0ac26c1c76b 100644 --- a/homeassistant/components/skybell/sensor.py +++ b/homeassistant/components/skybell/sensor.py @@ -71,4 +71,4 @@ class SkybellSensor(SkybellDevice, SensorEntity): super().update() if self.entity_description.key == "chime_level": - self._attr_state = self._device.outdoor_chime_level + self._attr_native_value = self._device.outdoor_chime_level diff --git a/homeassistant/components/sleepiq/sensor.py b/homeassistant/components/sleepiq/sensor.py index 8f5c17dad89..eec096e56c2 100644 --- a/homeassistant/components/sleepiq/sensor.py +++ b/homeassistant/components/sleepiq/sensor.py @@ -37,7 +37,7 @@ class SleepNumberSensor(SleepIQSensor, SensorEntity): self.update() @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return self._state diff --git a/homeassistant/components/sma/sensor.py b/homeassistant/components/sma/sensor.py index 6f3f7c2dca9..36084c53bb3 100644 --- a/homeassistant/components/sma/sensor.py +++ b/homeassistant/components/sma/sensor.py @@ -179,12 +179,12 @@ class SMAsensor(CoordinatorEntity, SensorEntity): return self._sensor.name @property - def state(self) -> StateType: + def native_value(self) -> StateType: """Return the state of the sensor.""" return self._sensor.value @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._sensor.unit diff --git a/homeassistant/components/smappee/sensor.py b/homeassistant/components/smappee/sensor.py index c7f30a8b954..fb879e3cef5 100644 --- a/homeassistant/components/smappee/sensor.py +++ b/homeassistant/components/smappee/sensor.py @@ -282,7 +282,7 @@ class SmappeeSensor(SensorEntity): return self._icon @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return self._state @@ -292,7 +292,7 @@ class SmappeeSensor(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/smart_meter_texas/sensor.py b/homeassistant/components/smart_meter_texas/sensor.py index f63edcce0fc..6914d3ef1ac 100644 --- a/homeassistant/components/smart_meter_texas/sensor.py +++ b/homeassistant/components/smart_meter_texas/sensor.py @@ -33,7 +33,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): class SmartMeterTexasSensor(CoordinatorEntity, RestoreEntity, SensorEntity): """Representation of an Smart Meter Texas sensor.""" - _attr_unit_of_measurement = ENERGY_KILO_WATT_HOUR + _attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR def __init__(self, meter: Meter, coordinator: DataUpdateCoordinator) -> None: """Initialize the sensor.""" @@ -58,7 +58,7 @@ class SmartMeterTexasSensor(CoordinatorEntity, RestoreEntity, SensorEntity): return self._available @property - def state(self): + def native_value(self): """Get the latest reading.""" return self._state diff --git a/homeassistant/components/smartthings/sensor.py b/homeassistant/components/smartthings/sensor.py index cb8fa4bb6d2..c4d84ec5f69 100644 --- a/homeassistant/components/smartthings/sensor.py +++ b/homeassistant/components/smartthings/sensor.py @@ -492,7 +492,7 @@ class SmartThingsSensor(SmartThingsEntity, SensorEntity): return f"{self._device.device_id}.{self._attribute}" @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return self._device.status.attributes[self._attribute].value @@ -502,7 +502,7 @@ class SmartThingsSensor(SmartThingsEntity, SensorEntity): return self._device_class @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit this state is expressed in.""" unit = self._device.status.attributes[self._attribute].unit return UNITS.get(unit, unit) if unit else self._default_unit @@ -534,7 +534,7 @@ class SmartThingsThreeAxisSensor(SmartThingsEntity, SensorEntity): return f"{self._device.device_id}.{THREE_AXIS_NAMES[self._index]}" @property - def state(self): + def native_value(self): """Return the state of the sensor.""" three_axis = self._device.status.attributes[Attribute.three_axis].value try: diff --git a/homeassistant/components/smarttub/sensor.py b/homeassistant/components/smarttub/sensor.py index 95a862502cd..9922792ba12 100644 --- a/homeassistant/components/smarttub/sensor.py +++ b/homeassistant/components/smarttub/sensor.py @@ -87,7 +87,7 @@ class SmartTubSensor(SmartTubSensorBase, SensorEntity): """Generic class for SmartTub status sensors.""" @property - def state(self) -> str: + def native_value(self) -> str: """Return the current state of the sensor.""" if isinstance(self._state, Enum): return self._state.name.lower() @@ -109,7 +109,7 @@ class SmartTubPrimaryFiltrationCycle(SmartTubSensor): return self._state @property - def state(self) -> str: + def native_value(self) -> str: """Return the current state of the sensor.""" return self.cycle.status.name.lower() @@ -147,7 +147,7 @@ class SmartTubSecondaryFiltrationCycle(SmartTubSensor): return self._state @property - def state(self) -> str: + def native_value(self) -> str: """Return the current state of the sensor.""" return self.cycle.status.name.lower() diff --git a/homeassistant/components/smarty/sensor.py b/homeassistant/components/smarty/sensor.py index b958185f9bd..a76e4b0f567 100644 --- a/homeassistant/components/smarty/sensor.py +++ b/homeassistant/components/smarty/sensor.py @@ -64,12 +64,12 @@ class SmartySensor(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 this state is expressed in.""" return self._unit_of_measurement diff --git a/homeassistant/components/sms/sensor.py b/homeassistant/components/sms/sensor.py index eb6c6ab22e1..d405c817656 100644 --- a/homeassistant/components/sms/sensor.py +++ b/homeassistant/components/sms/sensor.py @@ -25,7 +25,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): key="signal", name=f"gsm_signal_imei_{imei}", device_class=DEVICE_CLASS_SIGNAL_STRENGTH, - unit_of_measurement=SIGNAL_STRENGTH_DECIBELS, + native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS, entity_registry_enabled_default=False, ), ) @@ -55,7 +55,7 @@ class GSMSignalSensor(SensorEntity): return self._state is not None @property - def state(self): + def native_value(self): """Return the state of the device.""" return self._state["SignalStrength"] diff --git a/homeassistant/components/snmp/sensor.py b/homeassistant/components/snmp/sensor.py index 7de2bfb91e2..09bfe3856cc 100644 --- a/homeassistant/components/snmp/sensor.py +++ b/homeassistant/components/snmp/sensor.py @@ -155,12 +155,12 @@ class SnmpSensor(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/sochain/sensor.py b/homeassistant/components/sochain/sensor.py index 1f735da4995..a4cdd595f90 100644 --- a/homeassistant/components/sochain/sensor.py +++ b/homeassistant/components/sochain/sensor.py @@ -54,7 +54,7 @@ class SochainSensor(SensorEntity): return self._name @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return ( self.chainso.data.get("confirmed_balance") @@ -63,7 +63,7 @@ class SochainSensor(SensorEntity): ) @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/solaredge/const.py b/homeassistant/components/solaredge/const.py index 872781bf19c..06d8813130e 100644 --- a/homeassistant/components/solaredge/const.py +++ b/homeassistant/components/solaredge/const.py @@ -42,7 +42,7 @@ SENSOR_TYPES = [ icon="mdi:solar-power", last_reset=dt_util.utc_from_timestamp(0), state_class=STATE_CLASS_MEASUREMENT, - unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=ENERGY_WATT_HOUR, device_class=DEVICE_CLASS_ENERGY, ), SolarEdgeSensorEntityDescription( @@ -51,7 +51,7 @@ SENSOR_TYPES = [ name="Energy this year", entity_registry_enabled_default=False, icon="mdi:solar-power", - unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=ENERGY_WATT_HOUR, device_class=DEVICE_CLASS_ENERGY, ), SolarEdgeSensorEntityDescription( @@ -60,7 +60,7 @@ SENSOR_TYPES = [ name="Energy this month", entity_registry_enabled_default=False, icon="mdi:solar-power", - unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=ENERGY_WATT_HOUR, device_class=DEVICE_CLASS_ENERGY, ), SolarEdgeSensorEntityDescription( @@ -69,7 +69,7 @@ SENSOR_TYPES = [ name="Energy today", entity_registry_enabled_default=False, icon="mdi:solar-power", - unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=ENERGY_WATT_HOUR, device_class=DEVICE_CLASS_ENERGY, ), SolarEdgeSensorEntityDescription( @@ -78,7 +78,7 @@ SENSOR_TYPES = [ name="Current Power", icon="mdi:solar-power", state_class=STATE_CLASS_MEASUREMENT, - unit_of_measurement=POWER_WATT, + native_unit_of_measurement=POWER_WATT, device_class=DEVICE_CLASS_POWER, ), SolarEdgeSensorEntityDescription( @@ -185,6 +185,6 @@ SENSOR_TYPES = [ name="Storage Level", entity_registry_enabled_default=False, state_class=STATE_CLASS_MEASUREMENT, - unit_of_measurement=PERCENTAGE, + native_unit_of_measurement=PERCENTAGE, ), ] diff --git a/homeassistant/components/solaredge/sensor.py b/homeassistant/components/solaredge/sensor.py index 85e01a2d7ee..23aa269cf36 100644 --- a/homeassistant/components/solaredge/sensor.py +++ b/homeassistant/components/solaredge/sensor.py @@ -133,7 +133,7 @@ class SolarEdgeOverviewSensor(SolarEdgeSensorEntity): """Representation of an SolarEdge Monitoring API overview sensor.""" @property - def state(self) -> str | None: + def native_value(self) -> str | None: """Return the state of the sensor.""" return self.data_service.data.get(self.entity_description.json_key) @@ -147,7 +147,7 @@ class SolarEdgeDetailsSensor(SolarEdgeSensorEntity): return self.data_service.attributes @property - def state(self) -> str | None: + def native_value(self) -> str | None: """Return the state of the sensor.""" return self.data_service.data @@ -161,7 +161,7 @@ class SolarEdgeInventorySensor(SolarEdgeSensorEntity): return self.data_service.attributes.get(self.entity_description.json_key) @property - def state(self) -> str | None: + def native_value(self) -> str | None: """Return the state of the sensor.""" return self.data_service.data.get(self.entity_description.json_key) @@ -173,7 +173,7 @@ class SolarEdgeEnergyDetailsSensor(SolarEdgeSensorEntity): """Initialize the power flow sensor.""" super().__init__(platform_name, sensor_type, data_service) - self._attr_unit_of_measurement = data_service.unit + self._attr_native_unit_of_measurement = data_service.unit @property def extra_state_attributes(self) -> dict[str, Any]: @@ -181,7 +181,7 @@ class SolarEdgeEnergyDetailsSensor(SolarEdgeSensorEntity): return self.data_service.attributes.get(self.entity_description.json_key) @property - def state(self) -> str | None: + def native_value(self) -> str | None: """Return the state of the sensor.""" return self.data_service.data.get(self.entity_description.json_key) @@ -200,7 +200,7 @@ class SolarEdgePowerFlowSensor(SolarEdgeSensorEntity): """Initialize the power flow sensor.""" super().__init__(platform_name, description, data_service) - self._attr_unit_of_measurement = data_service.unit + self._attr_native_unit_of_measurement = data_service.unit @property def extra_state_attributes(self) -> dict[str, Any]: @@ -208,7 +208,7 @@ class SolarEdgePowerFlowSensor(SolarEdgeSensorEntity): return self.data_service.attributes.get(self.entity_description.json_key) @property - def state(self) -> str | None: + def native_value(self) -> str | None: """Return the state of the sensor.""" return self.data_service.data.get(self.entity_description.json_key) @@ -219,7 +219,7 @@ class SolarEdgeStorageLevelSensor(SolarEdgeSensorEntity): _attr_device_class = DEVICE_CLASS_BATTERY @property - def state(self) -> str | None: + def native_value(self) -> str | None: """Return the state of the sensor.""" attr = self.data_service.attributes.get(self.entity_description.json_key) if attr and "soc" in attr: diff --git a/homeassistant/components/solaredge_local/sensor.py b/homeassistant/components/solaredge_local/sensor.py index 3f159ce4480..f9ac2b853e7 100644 --- a/homeassistant/components/solaredge_local/sensor.py +++ b/homeassistant/components/solaredge_local/sensor.py @@ -285,7 +285,7 @@ class SolarEdgeSensor(SensorEntity): return f"{self._platform_name} ({self._name})" @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit of measurement.""" return self._unit_of_measurement @@ -305,7 +305,7 @@ class SolarEdgeSensor(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/solarlog/sensor.py b/homeassistant/components/solarlog/sensor.py index 85a1531090d..a6a35bad80c 100644 --- a/homeassistant/components/solarlog/sensor.py +++ b/homeassistant/components/solarlog/sensor.py @@ -82,7 +82,7 @@ class SolarlogSensor(SensorEntity): return f"{self.device_name} {self._label}" @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the state of the sensor.""" return self._unit_of_measurement @@ -92,7 +92,7 @@ class SolarlogSensor(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/solax/sensor.py b/homeassistant/components/solax/sensor.py index e47f5c57802..4d1652e8b12 100644 --- a/homeassistant/components/solax/sensor.py +++ b/homeassistant/components/solax/sensor.py @@ -84,7 +84,7 @@ class Inverter(SensorEntity): self.unit = unit @property - def state(self): + def native_value(self): """State of this inverter attribute.""" return self.value @@ -99,7 +99,7 @@ class Inverter(SensorEntity): return f"Solax {self.serial} {self.key}" @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/soma/sensor.py b/homeassistant/components/soma/sensor.py index 4df12c9f8f5..948e8d1e1e1 100644 --- a/homeassistant/components/soma/sensor.py +++ b/homeassistant/components/soma/sensor.py @@ -30,7 +30,7 @@ class SomaSensor(SomaEntity, SensorEntity): """Representation of a Soma cover device.""" _attr_device_class = DEVICE_CLASS_BATTERY - _attr_unit_of_measurement = PERCENTAGE + _attr_native_unit_of_measurement = PERCENTAGE @property def name(self): @@ -38,7 +38,7 @@ class SomaSensor(SomaEntity, SensorEntity): return self.device["name"] + " battery level" @property - def state(self): + def native_value(self): """Return the state of the entity.""" return self.battery_state diff --git a/homeassistant/components/somfy/sensor.py b/homeassistant/components/somfy/sensor.py index 1817ba3fd8c..9a0602cb592 100644 --- a/homeassistant/components/somfy/sensor.py +++ b/homeassistant/components/somfy/sensor.py @@ -30,7 +30,7 @@ class SomfyThermostatBatterySensor(SomfyEntity, SensorEntity): """Representation of a Somfy thermostat battery.""" _attr_device_class = DEVICE_CLASS_BATTERY - _attr_unit_of_measurement = PERCENTAGE + _attr_native_unit_of_measurement = PERCENTAGE def __init__(self, coordinator, device_id): """Initialize the Somfy device.""" @@ -43,6 +43,6 @@ class SomfyThermostatBatterySensor(SomfyEntity, SensorEntity): self._climate = Thermostat(self.device, self.coordinator.client) @property - def state(self) -> int: + def native_value(self) -> int: """Return the state of the sensor.""" return self._climate.get_battery() diff --git a/homeassistant/components/sonarr/sensor.py b/homeassistant/components/sonarr/sensor.py index d173d42eaf7..3f5ef275fef 100644 --- a/homeassistant/components/sonarr/sensor.py +++ b/homeassistant/components/sonarr/sensor.py @@ -85,7 +85,7 @@ class SonarrSensor(SonarrEntity, SensorEntity): self._attr_name = name self._attr_icon = icon self._attr_unique_id = f"{entry_id}_{key}" - self._attr_unit_of_measurement = unit_of_measurement + self._attr_native_unit_of_measurement = unit_of_measurement self._attr_entity_registry_enabled_default = enabled_default self.last_update_success = False @@ -134,7 +134,7 @@ class SonarrCommandsSensor(SonarrSensor): return attrs @property - def state(self) -> int: + def native_value(self) -> int: """Return the state of the sensor.""" return len(self._commands) @@ -181,7 +181,7 @@ class SonarrDiskspaceSensor(SonarrSensor): return attrs @property - def state(self) -> str: + def native_value(self) -> str: """Return the state of the sensor.""" free = self._total_free / 1024 ** 3 return f"{free:.2f}" @@ -223,7 +223,7 @@ class SonarrQueueSensor(SonarrSensor): return attrs @property - def state(self) -> int: + def native_value(self) -> int: """Return the state of the sensor.""" return len(self._queue) @@ -261,7 +261,7 @@ class SonarrSeriesSensor(SonarrSensor): return attrs @property - def state(self) -> int: + def native_value(self) -> int: """Return the state of the sensor.""" return len(self._items) @@ -304,7 +304,7 @@ class SonarrUpcomingSensor(SonarrSensor): return attrs @property - def state(self) -> int: + def native_value(self) -> int: """Return the state of the sensor.""" return len(self._upcoming) @@ -347,6 +347,6 @@ class SonarrWantedSensor(SonarrSensor): return attrs @property - def state(self) -> int | None: + def native_value(self) -> int | None: """Return the state of the sensor.""" return self._total diff --git a/homeassistant/components/sonos/sensor.py b/homeassistant/components/sonos/sensor.py index 9e5277819a7..1a13e6f55f4 100644 --- a/homeassistant/components/sonos/sensor.py +++ b/homeassistant/components/sonos/sensor.py @@ -45,7 +45,7 @@ class SonosBatteryEntity(SonosEntity, SensorEntity): return DEVICE_CLASS_BATTERY @property - def unit_of_measurement(self) -> str: + def native_unit_of_measurement(self) -> str: """Get the unit of measurement.""" return PERCENTAGE @@ -54,7 +54,7 @@ class SonosBatteryEntity(SonosEntity, SensorEntity): await self.speaker.async_poll_battery() @property - def state(self) -> int | None: + def native_value(self) -> int | None: """Return the state of the sensor.""" return self.speaker.battery_info.get("Level") diff --git a/homeassistant/components/speedtestdotnet/const.py b/homeassistant/components/speedtestdotnet/const.py index 897ffa126fa..c9962362406 100644 --- a/homeassistant/components/speedtestdotnet/const.py +++ b/homeassistant/components/speedtestdotnet/const.py @@ -17,19 +17,19 @@ SENSOR_TYPES: Final[tuple[SensorEntityDescription, ...]] = ( SensorEntityDescription( key="ping", name="Ping", - unit_of_measurement=TIME_MILLISECONDS, + native_unit_of_measurement=TIME_MILLISECONDS, state_class=STATE_CLASS_MEASUREMENT, ), SensorEntityDescription( key="download", name="Download", - unit_of_measurement=DATA_RATE_MEGABITS_PER_SECOND, + native_unit_of_measurement=DATA_RATE_MEGABITS_PER_SECOND, state_class=STATE_CLASS_MEASUREMENT, ), SensorEntityDescription( key="upload", name="Upload", - unit_of_measurement=DATA_RATE_MEGABITS_PER_SECOND, + native_unit_of_measurement=DATA_RATE_MEGABITS_PER_SECOND, state_class=STATE_CLASS_MEASUREMENT, ), ) diff --git a/homeassistant/components/speedtestdotnet/sensor.py b/homeassistant/components/speedtestdotnet/sensor.py index 1c6c80a6af1..2dc12c956de 100644 --- a/homeassistant/components/speedtestdotnet/sensor.py +++ b/homeassistant/components/speedtestdotnet/sensor.py @@ -85,7 +85,7 @@ class SpeedtestSensor(CoordinatorEntity, RestoreEntity, SensorEntity): await super().async_added_to_hass() state = await self.async_get_last_state() if state: - self._attr_state = state.state + self._attr_native_value = state.state @callback def update() -> None: @@ -100,8 +100,12 @@ class SpeedtestSensor(CoordinatorEntity, RestoreEntity, SensorEntity): """Update sensors state.""" if self.coordinator.data: if self.entity_description.key == "ping": - self._attr_state = self.coordinator.data["ping"] + self._attr_native_value = self.coordinator.data["ping"] elif self.entity_description.key == "download": - self._attr_state = round(self.coordinator.data["download"] / 10 ** 6, 2) + self._attr_native_value = round( + self.coordinator.data["download"] / 10 ** 6, 2 + ) elif self.entity_description.key == "upload": - self._attr_state = round(self.coordinator.data["upload"] / 10 ** 6, 2) + self._attr_native_value = round( + self.coordinator.data["upload"] / 10 ** 6, 2 + ) diff --git a/homeassistant/components/sql/sensor.py b/homeassistant/components/sql/sensor.py index 4c1c29b82a6..1b0ae5a9076 100644 --- a/homeassistant/components/sql/sensor.py +++ b/homeassistant/components/sql/sensor.py @@ -123,12 +123,12 @@ class SQLSensor(SensorEntity): return self._name @property - def state(self): + def native_value(self): """Return the query's current state.""" return self._state @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit of measurement.""" return self._unit_of_measurement diff --git a/homeassistant/components/srp_energy/sensor.py b/homeassistant/components/srp_energy/sensor.py index 6973c58600e..97b65840e83 100644 --- a/homeassistant/components/srp_energy/sensor.py +++ b/homeassistant/components/srp_energy/sensor.py @@ -93,14 +93,14 @@ class SrpEntity(SensorEntity): return self.type @property - def state(self): + def native_value(self): """Return the state of the device.""" if self._state: return f"{self._state:.2f}" return None @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/tests/components/sleepiq/test_sensor.py b/tests/components/sleepiq/test_sensor.py index c6a584802b9..7a7e47f03fa 100644 --- a/tests/components/sleepiq/test_sensor.py +++ b/tests/components/sleepiq/test_sensor.py @@ -21,15 +21,17 @@ async def test_setup(hass, requests_mock): assert len(devices) == 2 left_side = devices[1] + left_side.hass = hass assert left_side.name == "SleepNumber ILE Test1 SleepNumber" assert left_side.state == 40 right_side = devices[0] + right_side.hass = hass assert right_side.name == "SleepNumber ILE Test2 SleepNumber" assert right_side.state == 80 -async def test_setup_sigle(hass, requests_mock): +async def test_setup_single(hass, requests_mock): """Test for successfully setting up the SleepIQ platform.""" mock_responses(requests_mock, single=True) @@ -41,5 +43,6 @@ async def test_setup_sigle(hass, requests_mock): assert len(devices) == 1 right_side = devices[0] + right_side.hass = hass assert right_side.name == "SleepNumber ILE Test1 SleepNumber" assert right_side.state == 40 diff --git a/tests/components/srp_energy/test_sensor.py b/tests/components/srp_energy/test_sensor.py index 069dc9eb64f..3e830b7fc93 100644 --- a/tests/components/srp_energy/test_sensor.py +++ b/tests/components/srp_energy/test_sensor.py @@ -82,6 +82,7 @@ async def test_srp_entity(hass): """Test the SrpEntity.""" fake_coordinator = MagicMock(data=1.99999999999) srp_entity = SrpEntity(fake_coordinator) + srp_entity.hass = hass assert srp_entity is not None assert srp_entity.name == f"{DEFAULT_NAME} {SENSOR_NAME}" @@ -104,6 +105,7 @@ async def test_srp_entity_no_data(hass): """Test the SrpEntity.""" fake_coordinator = MagicMock(data=False) srp_entity = SrpEntity(fake_coordinator) + srp_entity.hass = hass assert srp_entity.extra_state_attributes is None @@ -111,6 +113,7 @@ async def test_srp_entity_no_coord_data(hass): """Test the SrpEntity.""" fake_coordinator = MagicMock(data=False) srp_entity = SrpEntity(fake_coordinator) + srp_entity.hass = hass assert srp_entity.usage is None @@ -124,6 +127,7 @@ async def test_srp_entity_async_update(hass): MagicMock.__await__ = lambda x: async_magic().__await__() fake_coordinator = MagicMock(data=False) srp_entity = SrpEntity(fake_coordinator) + srp_entity.hass = hass await srp_entity.async_update() assert fake_coordinator.async_request_refresh.called