diff --git a/homeassistant/components/iammeter/sensor.py b/homeassistant/components/iammeter/sensor.py index b1882619fda..de0e76fc3aa 100644 --- a/homeassistant/components/iammeter/sensor.py +++ b/homeassistant/components/iammeter/sensor.py @@ -86,7 +86,7 @@ class IamMeter(CoordinatorEntity, SensorEntity): self.dev_name = dev_name @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return self.coordinator.data.data[self.sensor_name] @@ -106,6 +106,6 @@ class IamMeter(CoordinatorEntity, SensorEntity): return "mdi:flash" @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/iaqualink/sensor.py b/homeassistant/components/iaqualink/sensor.py index ae32db9eb9e..61e4560c3be 100644 --- a/homeassistant/components/iaqualink/sensor.py +++ b/homeassistant/components/iaqualink/sensor.py @@ -31,7 +31,7 @@ class HassAqualinkSensor(AqualinkEntity, SensorEntity): return self.dev.label @property - def unit_of_measurement(self) -> str | None: + def native_unit_of_measurement(self) -> str | None: """Return the measurement unit for the sensor.""" if self.dev.name.endswith("_temp"): if self.dev.system.temp_unit == "F": @@ -40,7 +40,7 @@ class HassAqualinkSensor(AqualinkEntity, SensorEntity): return None @property - def state(self) -> str | None: + def native_value(self) -> str | None: """Return the state of the sensor.""" if self.dev.state == "": return None diff --git a/homeassistant/components/icloud/sensor.py b/homeassistant/components/icloud/sensor.py index ec55a1fcedd..5469eadc998 100644 --- a/homeassistant/components/icloud/sensor.py +++ b/homeassistant/components/icloud/sensor.py @@ -54,7 +54,7 @@ class IcloudDeviceBatterySensor(SensorEntity): """Representation of a iCloud device battery sensor.""" _attr_device_class = DEVICE_CLASS_BATTERY - _attr_unit_of_measurement = PERCENTAGE + _attr_native_unit_of_measurement = PERCENTAGE def __init__(self, account: IcloudAccount, device: IcloudDevice) -> None: """Initialize the battery sensor.""" @@ -73,7 +73,7 @@ class IcloudDeviceBatterySensor(SensorEntity): return f"{self._device.name} battery state" @property - def state(self) -> int: + def native_value(self) -> int: """Battery state percentage.""" return self._device.battery_level diff --git a/homeassistant/components/ihc/sensor.py b/homeassistant/components/ihc/sensor.py index d1aec781df7..17c17980c95 100644 --- a/homeassistant/components/ihc/sensor.py +++ b/homeassistant/components/ihc/sensor.py @@ -48,12 +48,12 @@ class IHCSensor(IHCDevice, SensorEntity): ) @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/imap/sensor.py b/homeassistant/components/imap/sensor.py index 4158d1be801..c3d6b2198ce 100644 --- a/homeassistant/components/imap/sensor.py +++ b/homeassistant/components/imap/sensor.py @@ -95,7 +95,7 @@ class ImapSensor(SensorEntity): return ICON @property - def state(self): + def native_value(self): """Return the number of emails found.""" return self._email_count diff --git a/homeassistant/components/imap_email_content/sensor.py b/homeassistant/components/imap_email_content/sensor.py index cdd47d68d76..87c18a56bbe 100644 --- a/homeassistant/components/imap_email_content/sensor.py +++ b/homeassistant/components/imap_email_content/sensor.py @@ -165,7 +165,7 @@ class EmailContentSensor(SensorEntity): return self._name @property - def state(self): + def native_value(self): """Return the current email state.""" return self._message diff --git a/homeassistant/components/incomfort/sensor.py b/homeassistant/components/incomfort/sensor.py index a9e1faaba10..9fb99321ff2 100644 --- a/homeassistant/components/incomfort/sensor.py +++ b/homeassistant/components/incomfort/sensor.py @@ -59,7 +59,7 @@ class IncomfortSensor(IncomfortChild, SensorEntity): self._unit_of_measurement = None @property - def state(self) -> str | None: + def native_value(self) -> str | None: """Return the state of the sensor.""" return self._heater.status[self._state_attr] @@ -69,7 +69,7 @@ class IncomfortSensor(IncomfortChild, SensorEntity): return self._device_class @property - def unit_of_measurement(self) -> str | None: + def native_unit_of_measurement(self) -> str | None: """Return the unit of measurement of the sensor.""" return self._unit_of_measurement diff --git a/homeassistant/components/influxdb/sensor.py b/homeassistant/components/influxdb/sensor.py index c2cb5070a4c..bdbfafaf790 100644 --- a/homeassistant/components/influxdb/sensor.py +++ b/homeassistant/components/influxdb/sensor.py @@ -222,12 +222,12 @@ class InfluxSensor(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/integration/sensor.py b/homeassistant/components/integration/sensor.py index 9308adc622d..cabcb2fd394 100644 --- a/homeassistant/components/integration/sensor.py +++ b/homeassistant/components/integration/sensor.py @@ -213,12 +213,12 @@ class IntegrationSensor(RestoreEntity, SensorEntity): return self._name @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return round(self._state, self._round_digits) @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/ios/sensor.py b/homeassistant/components/ios/sensor.py index d3b006f9078..c3c1ad2b8ce 100644 --- a/homeassistant/components/ios/sensor.py +++ b/homeassistant/components/ios/sensor.py @@ -14,7 +14,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="level", name="Battery Level", - unit_of_measurement=PERCENTAGE, + native_unit_of_measurement=PERCENTAGE, ), SensorEntityDescription( key="state", @@ -114,12 +114,16 @@ class IOSSensor(SensorEntity): def _update(self, device): """Get the latest state of the sensor.""" self._device = device - self._attr_state = self._device[ios.ATTR_BATTERY][self.entity_description.key] + self._attr_native_value = self._device[ios.ATTR_BATTERY][ + self.entity_description.key + ] self.async_write_ha_state() async def async_added_to_hass(self) -> None: """Added to hass so need to register to dispatch.""" - self._attr_state = self._device[ios.ATTR_BATTERY][self.entity_description.key] + self._attr_native_value = self._device[ios.ATTR_BATTERY][ + self.entity_description.key + ] device_id = self._device[ios.ATTR_DEVICE_ID] self.async_on_remove( async_dispatcher_connect(self.hass, f"{DOMAIN}.{device_id}", self._update) diff --git a/homeassistant/components/iota/sensor.py b/homeassistant/components/iota/sensor.py index 62260be2410..687a4ca35d6 100644 --- a/homeassistant/components/iota/sensor.py +++ b/homeassistant/components/iota/sensor.py @@ -47,12 +47,12 @@ class IotaBalanceSensor(IotaDevice, SensorEntity): return f"{self._name} Balance" @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.""" return "IOTA" @@ -81,7 +81,7 @@ class IotaNodeSensor(IotaDevice, SensorEntity): return "IOTA Node" @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return self._state diff --git a/homeassistant/components/iperf3/sensor.py b/homeassistant/components/iperf3/sensor.py index 610ff91250f..07b9cc069e4 100644 --- a/homeassistant/components/iperf3/sensor.py +++ b/homeassistant/components/iperf3/sensor.py @@ -41,12 +41,12 @@ class Iperf3Sensor(RestoreEntity, SensorEntity): return self._name @property - def state(self): + def native_value(self): """Return the state of the device.""" 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/ipp/sensor.py b/homeassistant/components/ipp/sensor.py index 5d736c864e1..e7c0d5c38f5 100644 --- a/homeassistant/components/ipp/sensor.py +++ b/homeassistant/components/ipp/sensor.py @@ -72,7 +72,7 @@ class IPPSensor(IPPEntity, SensorEntity): """Initialize IPP sensor.""" self._key = key self._attr_unique_id = f"{unique_id}_{key}" - self._attr_unit_of_measurement = unit_of_measurement + self._attr_native_unit_of_measurement = unit_of_measurement super().__init__( entry_id=entry_id, @@ -123,7 +123,7 @@ class IPPMarkerSensor(IPPSensor): } @property - def state(self) -> int | None: + def native_value(self) -> int | None: """Return the state of the sensor.""" level = self.coordinator.data.markers[self.marker_index].level @@ -164,7 +164,7 @@ class IPPPrinterSensor(IPPSensor): } @property - def state(self) -> str: + def native_value(self) -> str: """Return the state of the sensor.""" return self.coordinator.data.state.printer_state @@ -189,7 +189,7 @@ class IPPUptimeSensor(IPPSensor): ) @property - def state(self) -> str: + def native_value(self) -> str: """Return the state of the sensor.""" uptime = utcnow() - timedelta(seconds=self.coordinator.data.info.uptime) return uptime.replace(microsecond=0).isoformat() diff --git a/homeassistant/components/iqvia/__init__.py b/homeassistant/components/iqvia/__init__.py index fa783cc9031..37cc7bedb71 100644 --- a/homeassistant/components/iqvia/__init__.py +++ b/homeassistant/components/iqvia/__init__.py @@ -109,7 +109,7 @@ class IQVIAEntity(CoordinatorEntity, SensorEntity): self._attr_icon = icon self._attr_name = name self._attr_unique_id = f"{entry.data[CONF_ZIP_CODE]}_{sensor_type}" - self._attr_unit_of_measurement = "index" + self._attr_native_unit_of_measurement = "index" self._entry = entry self._type = sensor_type diff --git a/homeassistant/components/iqvia/sensor.py b/homeassistant/components/iqvia/sensor.py index 5762e4a3888..10d33bfb4bf 100644 --- a/homeassistant/components/iqvia/sensor.py +++ b/homeassistant/components/iqvia/sensor.py @@ -120,7 +120,7 @@ class ForecastSensor(IQVIAEntity): if i["minimum"] <= average <= i["maximum"] ] - self._attr_state = average + self._attr_native_value = average self._attr_extra_state_attributes.update( { ATTR_CITY: data["City"].title(), @@ -213,4 +213,4 @@ class IndexSensor(IQVIAEntity): f"{attrs['Name'].lower()}_index" ] = attrs["Index"] - self._attr_state = period["Index"] + self._attr_native_value = period["Index"] diff --git a/homeassistant/components/irish_rail_transport/sensor.py b/homeassistant/components/irish_rail_transport/sensor.py index b5ba16f8541..9ec28d73836 100644 --- a/homeassistant/components/irish_rail_transport/sensor.py +++ b/homeassistant/components/irish_rail_transport/sensor.py @@ -83,7 +83,7 @@ class IrishRailTransportSensor(SensorEntity): return self._name @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return self._state @@ -114,7 +114,7 @@ class IrishRailTransportSensor(SensorEntity): } @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/islamic_prayer_times/sensor.py b/homeassistant/components/islamic_prayer_times/sensor.py index 2fa563785d2..99cc65bb548 100644 --- a/homeassistant/components/islamic_prayer_times/sensor.py +++ b/homeassistant/components/islamic_prayer_times/sensor.py @@ -43,7 +43,7 @@ class IslamicPrayerTimeSensor(SensorEntity): return self.sensor_type @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return ( self.client.prayer_times_info.get(self.sensor_type) diff --git a/homeassistant/components/isy994/sensor.py b/homeassistant/components/isy994/sensor.py index ebf32384d85..f12f3cb6bdd 100644 --- a/homeassistant/components/isy994/sensor.py +++ b/homeassistant/components/isy994/sensor.py @@ -67,7 +67,7 @@ class ISYSensorEntity(ISYNodeEntity, SensorEntity): return UOM_FRIENDLY_NAME.get(uom) @property - def state(self) -> str: + def native_value(self) -> str: """Get the state of the ISY994 sensor device.""" value = self._node.status if value == ISY_VALUE_UNKNOWN: @@ -97,7 +97,7 @@ class ISYSensorEntity(ISYNodeEntity, SensorEntity): return value @property - def unit_of_measurement(self) -> str: + def native_unit_of_measurement(self) -> str: """Get the Home Assistant unit of measurement for the device.""" raw_units = self.raw_unit_of_measurement # Check if this is a known index pair UOM @@ -117,7 +117,7 @@ class ISYSensorVariableEntity(ISYEntity, SensorEntity): self._name = vname @property - def state(self): + def native_value(self): """Return the state of the variable.""" return convert_isy_value_to_hass(self._node.status, "", self._node.prec) diff --git a/homeassistant/components/jewish_calendar/sensor.py b/homeassistant/components/jewish_calendar/sensor.py index 17a61c932a3..e3f51ea5e2c 100644 --- a/homeassistant/components/jewish_calendar/sensor.py +++ b/homeassistant/components/jewish_calendar/sensor.py @@ -50,7 +50,7 @@ class JewishCalendarSensor(SensorEntity): self._holiday_attrs = {} @property - def state(self): + def native_value(self): """Return the state of the sensor.""" if isinstance(self._state, datetime): return self._state.isoformat() @@ -134,7 +134,7 @@ class JewishCalendarTimeSensor(JewishCalendarSensor): _attr_device_class = DEVICE_CLASS_TIMESTAMP @property - def state(self): + def native_value(self): """Return the state of the sensor.""" if self._state is None: return None diff --git a/homeassistant/components/juicenet/sensor.py b/homeassistant/components/juicenet/sensor.py index 435508f823d..4eaaba41b55 100644 --- a/homeassistant/components/juicenet/sensor.py +++ b/homeassistant/components/juicenet/sensor.py @@ -31,40 +31,40 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="temperature", name="Temperature", - unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=TEMP_CELSIUS, device_class=DEVICE_CLASS_TEMPERATURE, state_class=STATE_CLASS_MEASUREMENT, ), SensorEntityDescription( key="voltage", name="Voltage", - unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, + native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, device_class=DEVICE_CLASS_VOLTAGE, ), SensorEntityDescription( key="amps", name="Amps", - unit_of_measurement=ELECTRIC_CURRENT_AMPERE, + native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE, device_class=DEVICE_CLASS_CURRENT, state_class=STATE_CLASS_MEASUREMENT, ), SensorEntityDescription( key="watts", name="Watts", - unit_of_measurement=POWER_WATT, + native_unit_of_measurement=POWER_WATT, device_class=DEVICE_CLASS_POWER, state_class=STATE_CLASS_MEASUREMENT, ), SensorEntityDescription( key="charge_time", name="Charge time", - unit_of_measurement=TIME_SECONDS, + native_unit_of_measurement=TIME_SECONDS, icon="mdi:timer-outline", ), SensorEntityDescription( key="energy_added", name="Energy added", - unit_of_measurement=ENERGY_WATT_HOUR, + native_unit_of_measurement=ENERGY_WATT_HOUR, device_class=DEVICE_CLASS_ENERGY, ), ) @@ -110,6 +110,6 @@ class JuiceNetSensorDevice(JuiceNetDevice, SensorEntity): return icon @property - def state(self): + def native_value(self): """Return the state.""" return getattr(self.device, self.entity_description.key, None) diff --git a/homeassistant/components/kaiterra/sensor.py b/homeassistant/components/kaiterra/sensor.py index 6c82013361a..fbaa730ab9f 100644 --- a/homeassistant/components/kaiterra/sensor.py +++ b/homeassistant/components/kaiterra/sensor.py @@ -70,7 +70,7 @@ class KaiterraSensor(SensorEntity): return self._name @property - def state(self): + def native_value(self): """Return the state.""" return self._sensor.get("value") @@ -80,7 +80,7 @@ class KaiterraSensor(SensorEntity): return f"{self._device_id}_{self._kind}" @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit the value is expressed in.""" if not self._sensor.get("units"): return None diff --git a/homeassistant/components/keba/sensor.py b/homeassistant/components/keba/sensor.py index 2792246d71c..37b42cb3cbe 100644 --- a/homeassistant/components/keba/sensor.py +++ b/homeassistant/components/keba/sensor.py @@ -104,12 +104,12 @@ class KebaSensor(SensorEntity): return self._icon @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): """Get the unit of measurement.""" return self._unit diff --git a/homeassistant/components/kira/sensor.py b/homeassistant/components/kira/sensor.py index a6b1b9ada22..b28aac740f1 100644 --- a/homeassistant/components/kira/sensor.py +++ b/homeassistant/components/kira/sensor.py @@ -50,7 +50,7 @@ class KiraReceiver(SensorEntity): return ICON @property - def state(self): + def native_value(self): """Return the state of the receiver.""" return self._state diff --git a/homeassistant/components/knx/sensor.py b/homeassistant/components/knx/sensor.py index 5fee8446e91..933ba7bf30d 100644 --- a/homeassistant/components/knx/sensor.py +++ b/homeassistant/components/knx/sensor.py @@ -62,11 +62,11 @@ class KNXSensor(KnxEntity, SensorEntity): ) self._attr_force_update = self._device.always_callback self._attr_unique_id = str(self._device.sensor_value.group_address_state) - self._attr_unit_of_measurement = self._device.unit_of_measurement() + self._attr_native_unit_of_measurement = self._device.unit_of_measurement() self._attr_state_class = config.get(SensorSchema.CONF_STATE_CLASS) @property - def state(self) -> StateType: + def native_value(self) -> StateType: """Return the state of the sensor.""" return self._device.resolve_state() diff --git a/homeassistant/components/konnected/sensor.py b/homeassistant/components/konnected/sensor.py index 18975bdb467..a22b30f6862 100644 --- a/homeassistant/components/konnected/sensor.py +++ b/homeassistant/components/konnected/sensor.py @@ -104,12 +104,12 @@ class KonnectedSensor(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.""" return self._unit_of_measurement diff --git a/homeassistant/components/kostal_plenticore/sensor.py b/homeassistant/components/kostal_plenticore/sensor.py index 099d359e619..57b37e51d11 100644 --- a/homeassistant/components/kostal_plenticore/sensor.py +++ b/homeassistant/components/kostal_plenticore/sensor.py @@ -169,7 +169,7 @@ class PlenticoreDataSensor(CoordinatorEntity, SensorEntity): return f"{self.platform_name} {self._sensor_name}" @property - def unit_of_measurement(self) -> str | None: + def native_unit_of_measurement(self) -> str | None: """Return the unit of this Sensor Entity or None.""" return self._sensor_data.get(ATTR_UNIT_OF_MEASUREMENT) @@ -199,7 +199,7 @@ class PlenticoreDataSensor(CoordinatorEntity, SensorEntity): return self._sensor_data.get(ATTR_LAST_RESET) @property - def state(self) -> Any | None: + def native_value(self) -> Any | None: """Return the state of the sensor.""" if self.coordinator.data is None: # None is translated to STATE_UNKNOWN diff --git a/homeassistant/components/kraken/sensor.py b/homeassistant/components/kraken/sensor.py index bc0a0a21845..1b9f8ca13cc 100644 --- a/homeassistant/components/kraken/sensor.py +++ b/homeassistant/components/kraken/sensor.py @@ -124,7 +124,7 @@ class KrakenSensor(CoordinatorEntity, SensorEntity): return self._name.lower() @property - def state(self) -> StateType: + def native_value(self) -> StateType: """Return the state.""" return self._state @@ -229,7 +229,7 @@ class KrakenSensor(CoordinatorEntity, SensorEntity): return "mdi:cash" @property - def unit_of_measurement(self) -> str | None: + def native_unit_of_measurement(self) -> str | None: """Return the unit the value is expressed in.""" if "number_of" not in self._sensor_type: return self._unit_of_measurement diff --git a/homeassistant/components/kwb/sensor.py b/homeassistant/components/kwb/sensor.py index 1b56803fae6..c6d2794a06d 100644 --- a/homeassistant/components/kwb/sensor.py +++ b/homeassistant/components/kwb/sensor.py @@ -94,13 +94,13 @@ class KWBSensor(SensorEntity): return self._sensor.available @property - def state(self): + def native_value(self): """Return the state of value.""" if self._sensor.value is not None and self._sensor.available: return self._sensor.value 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._sensor.unit_of_measurement diff --git a/homeassistant/components/lacrosse/sensor.py b/homeassistant/components/lacrosse/sensor.py index 2f93196a4bb..99aa39ce7cd 100644 --- a/homeassistant/components/lacrosse/sensor.py +++ b/homeassistant/components/lacrosse/sensor.py @@ -176,10 +176,10 @@ class LaCrosseTemperature(LaCrosseSensor): """Implementation of a Lacrosse temperature sensor.""" _attr_device_class = DEVICE_CLASS_TEMPERATURE - _attr_unit_of_measurement = TEMP_CELSIUS + _attr_native_unit_of_measurement = TEMP_CELSIUS @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return self._temperature @@ -187,11 +187,11 @@ class LaCrosseTemperature(LaCrosseSensor): class LaCrosseHumidity(LaCrosseSensor): """Implementation of a Lacrosse humidity sensor.""" - _attr_unit_of_measurement = PERCENTAGE + _attr_native_unit_of_measurement = PERCENTAGE _attr_icon = "mdi:water-percent" @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return self._humidity @@ -200,7 +200,7 @@ class LaCrosseBattery(LaCrosseSensor): """Implementation of a Lacrosse battery sensor.""" @property - def state(self): + def native_value(self): """Return the state of the sensor.""" if self._low_battery is None: return None diff --git a/homeassistant/components/lastfm/sensor.py b/homeassistant/components/lastfm/sensor.py index 128450826d6..66f05c5d34d 100644 --- a/homeassistant/components/lastfm/sensor.py +++ b/homeassistant/components/lastfm/sensor.py @@ -77,7 +77,7 @@ class LastfmSensor(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/launch_library/sensor.py b/homeassistant/components/launch_library/sensor.py index 68d2a024bca..18a947f7757 100644 --- a/homeassistant/components/launch_library/sensor.py +++ b/homeassistant/components/launch_library/sensor.py @@ -59,7 +59,7 @@ class LaunchLibrarySensor(SensorEntity): else: if next_launch := next((launch for launch in launches), None): self._attr_available = True - self._attr_state = next_launch.name + self._attr_native_value = next_launch.name self._attr_extra_state_attributes = { ATTR_LAUNCH_TIME: next_launch.net, ATTR_AGENCY: next_launch.launch_service_provider.name, diff --git a/homeassistant/components/lcn/sensor.py b/homeassistant/components/lcn/sensor.py index fdd6ee51872..965e9626f66 100644 --- a/homeassistant/components/lcn/sensor.py +++ b/homeassistant/components/lcn/sensor.py @@ -93,12 +93,12 @@ class LcnVariableSensor(LcnEntity, SensorEntity): await self.device_connection.cancel_status_request_handler(self.variable) @property - def state(self) -> str | None: + def native_value(self) -> str | None: """Return the state of the entity.""" return self._value @property - def unit_of_measurement(self) -> str: + def native_unit_of_measurement(self) -> str: """Return the unit of measurement of this entity, if any.""" return cast(str, self.unit.value) @@ -145,7 +145,7 @@ class LcnLedLogicSensor(LcnEntity, SensorEntity): await self.device_connection.cancel_status_request_handler(self.source) @property - def state(self) -> str | None: + def native_value(self) -> str | None: """Return the state of the entity.""" return self._value diff --git a/homeassistant/components/lightwave/sensor.py b/homeassistant/components/lightwave/sensor.py index b298b78c7f6..369256ce403 100644 --- a/homeassistant/components/lightwave/sensor.py +++ b/homeassistant/components/lightwave/sensor.py @@ -26,7 +26,7 @@ class LightwaveBattery(SensorEntity): """Lightwave TRV Battery.""" _attr_device_class = DEVICE_CLASS_BATTERY - _attr_unit_of_measurement = PERCENTAGE + _attr_native_unit_of_measurement = PERCENTAGE _attr_state_class = STATE_CLASS_MEASUREMENT def __init__(self, name, lwlink, serial): @@ -43,7 +43,7 @@ class LightwaveBattery(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/linux_battery/sensor.py b/homeassistant/components/linux_battery/sensor.py index b7746392cee..18f1c81e368 100644 --- a/homeassistant/components/linux_battery/sensor.py +++ b/homeassistant/components/linux_battery/sensor.py @@ -90,12 +90,12 @@ class LinuxBatterySensor(SensorEntity): return DEVICE_CLASS_BATTERY @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return self._battery_stat.capacity @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit the value is expressed in.""" return PERCENTAGE diff --git a/homeassistant/components/litterrobot/sensor.py b/homeassistant/components/litterrobot/sensor.py index 15ea68f8342..cbcb75c0b23 100644 --- a/homeassistant/components/litterrobot/sensor.py +++ b/homeassistant/components/litterrobot/sensor.py @@ -36,7 +36,7 @@ class LitterRobotPropertySensor(LitterRobotEntity, SensorEntity): self.sensor_attribute = sensor_attribute @property - def state(self) -> str: + def native_value(self) -> str: """Return the state.""" return getattr(self.robot, self.sensor_attribute) @@ -45,7 +45,7 @@ class LitterRobotWasteSensor(LitterRobotPropertySensor): """Litter-Robot waste sensor.""" @property - def unit_of_measurement(self) -> str: + def native_unit_of_measurement(self) -> str: """Return unit of measurement.""" return PERCENTAGE @@ -59,10 +59,10 @@ class LitterRobotSleepTimeSensor(LitterRobotPropertySensor): """Litter-Robot sleep time sensor.""" @property - def state(self) -> str | None: + def native_value(self) -> str | None: """Return the state.""" if self.robot.sleep_mode_enabled: - return super().state.isoformat() + return super().native_value.isoformat() return None @property diff --git a/homeassistant/components/local_ip/sensor.py b/homeassistant/components/local_ip/sensor.py index 661ef88e641..bd1b3d54fac 100644 --- a/homeassistant/components/local_ip/sensor.py +++ b/homeassistant/components/local_ip/sensor.py @@ -33,6 +33,6 @@ class IPSensor(SensorEntity): async def async_update(self) -> None: """Fetch new state data for the sensor.""" - self._attr_state = await async_get_source_ip( + self._attr_native_value = await async_get_source_ip( self.hass, target_ip=PUBLIC_TARGET_IP ) diff --git a/homeassistant/components/logi_circle/sensor.py b/homeassistant/components/logi_circle/sensor.py index 29cd6e28e1c..a4158762b37 100644 --- a/homeassistant/components/logi_circle/sensor.py +++ b/homeassistant/components/logi_circle/sensor.py @@ -67,7 +67,7 @@ class LogiSensor(SensorEntity): return self._name @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return self._state @@ -112,7 +112,7 @@ class LogiSensor(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)[1] diff --git a/homeassistant/components/london_air/sensor.py b/homeassistant/components/london_air/sensor.py index 23eea5c00e0..23bc67f46bc 100644 --- a/homeassistant/components/london_air/sensor.py +++ b/homeassistant/components/london_air/sensor.py @@ -108,7 +108,7 @@ class AirSensor(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/london_underground/sensor.py b/homeassistant/components/london_underground/sensor.py index b7f2cb50cbf..eb962772fe5 100644 --- a/homeassistant/components/london_underground/sensor.py +++ b/homeassistant/components/london_underground/sensor.py @@ -67,7 +67,7 @@ class LondonTubeSensor(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/loopenergy/sensor.py b/homeassistant/components/loopenergy/sensor.py index 78e55f22eb8..05d7f79ebfd 100644 --- a/homeassistant/components/loopenergy/sensor.py +++ b/homeassistant/components/loopenergy/sensor.py @@ -97,7 +97,7 @@ class LoopEnergySensor(SensorEntity): return self._name @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return self._state @@ -107,7 +107,7 @@ class LoopEnergySensor(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/luftdaten/sensor.py b/homeassistant/components/luftdaten/sensor.py index b27cc35ab26..b4bdd7f30b3 100644 --- a/homeassistant/components/luftdaten/sensor.py +++ b/homeassistant/components/luftdaten/sensor.py @@ -73,7 +73,7 @@ class LuftdatenSensor(SensorEntity): return self._icon @property - def state(self): + def native_value(self): """Return the state of the device.""" if self._data is not None: try: @@ -82,7 +82,7 @@ class LuftdatenSensor(SensorEntity): 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/homeassistant/components/lyft/sensor.py b/homeassistant/components/lyft/sensor.py index 39cfff38a1b..84e3744a0e2 100644 --- a/homeassistant/components/lyft/sensor.py +++ b/homeassistant/components/lyft/sensor.py @@ -103,12 +103,12 @@ class LyftSensor(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/lyric/sensor.py b/homeassistant/components/lyric/sensor.py index f4d4d4b999a..868b6262ddc 100644 --- a/homeassistant/components/lyric/sensor.py +++ b/homeassistant/components/lyric/sensor.py @@ -94,7 +94,7 @@ class LyricSensor(LyricDeviceEntity, SensorEntity): return self._device_class @property - def unit_of_measurement(self) -> str: + def native_unit_of_measurement(self) -> str: """Return the unit this state is expressed in.""" return self._unit_of_measurement @@ -123,7 +123,7 @@ class LyricIndoorTemperatureSensor(LyricSensor): ) @property - def state(self) -> str: + def native_value(self) -> str: """Return the state of the sensor.""" return self.device.indoorTemperature @@ -152,7 +152,7 @@ class LyricOutdoorTemperatureSensor(LyricSensor): ) @property - def state(self) -> str: + def native_value(self) -> str: """Return the state of the sensor.""" return self.device.outdoorTemperature @@ -181,7 +181,7 @@ class LyricOutdoorHumiditySensor(LyricSensor): ) @property - def state(self) -> str: + def native_value(self) -> str: """Return the state of the sensor.""" return self.device.displayedOutdoorHumidity @@ -209,7 +209,7 @@ class LyricNextPeriodSensor(LyricSensor): ) @property - def state(self) -> datetime: + def native_value(self) -> datetime: """Return the state of the sensor.""" device = self.device time = dt_util.parse_time(device.changeableValues.nextPeriodTime) @@ -242,7 +242,7 @@ class LyricSetpointStatusSensor(LyricSensor): ) @property - def state(self) -> str: + def native_value(self) -> str: """Return the state of the sensor.""" device = self.device if device.changeableValues.thermostatSetpointStatus == PRESET_HOLD_UNTIL: diff --git a/homeassistant/components/magicseaweed/sensor.py b/homeassistant/components/magicseaweed/sensor.py index 0dd27a60ae0..12288c5ab78 100644 --- a/homeassistant/components/magicseaweed/sensor.py +++ b/homeassistant/components/magicseaweed/sensor.py @@ -115,7 +115,7 @@ class MagicSeaweedSensor(SensorEntity): return f"{self.hour} {self.client_name} {self._name}" @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return self._state @@ -125,7 +125,7 @@ class MagicSeaweedSensor(SensorEntity): return self._unit_system @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/mazda/sensor.py b/homeassistant/components/mazda/sensor.py index 673c965544b..03bfbd23b31 100644 --- a/homeassistant/components/mazda/sensor.py +++ b/homeassistant/components/mazda/sensor.py @@ -46,7 +46,7 @@ class MazdaFuelRemainingSensor(MazdaEntity, SensorEntity): return f"{self.vin}_fuel_remaining_percentage" @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit of measurement.""" return PERCENTAGE @@ -56,7 +56,7 @@ class MazdaFuelRemainingSensor(MazdaEntity, SensorEntity): return "mdi:gas-station" @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return self.data["status"]["fuelRemainingPercent"] @@ -76,7 +76,7 @@ class MazdaFuelDistanceSensor(MazdaEntity, SensorEntity): return f"{self.vin}_fuel_distance_remaining" @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit of measurement.""" if self.hass.config.units.name == CONF_UNIT_SYSTEM_IMPERIAL: return LENGTH_MILES @@ -88,7 +88,7 @@ class MazdaFuelDistanceSensor(MazdaEntity, SensorEntity): return "mdi:gas-station" @property - def state(self): + def native_value(self): """Return the state of the sensor.""" fuel_distance_km = self.data["status"]["fuelDistanceRemainingKm"] return ( @@ -115,7 +115,7 @@ class MazdaOdometerSensor(MazdaEntity, SensorEntity): return f"{self.vin}_odometer" @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit of measurement.""" if self.hass.config.units.name == CONF_UNIT_SYSTEM_IMPERIAL: return LENGTH_MILES @@ -127,7 +127,7 @@ class MazdaOdometerSensor(MazdaEntity, SensorEntity): return "mdi:speedometer" @property - def state(self): + def native_value(self): """Return the state of the sensor.""" odometer_km = self.data["status"]["odometerKm"] return ( @@ -152,7 +152,7 @@ class MazdaFrontLeftTirePressureSensor(MazdaEntity, SensorEntity): return f"{self.vin}_front_left_tire_pressure" @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit of measurement.""" return PRESSURE_PSI @@ -162,7 +162,7 @@ class MazdaFrontLeftTirePressureSensor(MazdaEntity, SensorEntity): return "mdi:car-tire-alert" @property - def state(self): + def native_value(self): """Return the state of the sensor.""" tire_pressure = self.data["status"]["tirePressure"]["frontLeftTirePressurePsi"] return None if tire_pressure is None else round(tire_pressure) @@ -183,7 +183,7 @@ class MazdaFrontRightTirePressureSensor(MazdaEntity, SensorEntity): return f"{self.vin}_front_right_tire_pressure" @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit of measurement.""" return PRESSURE_PSI @@ -193,7 +193,7 @@ class MazdaFrontRightTirePressureSensor(MazdaEntity, SensorEntity): return "mdi:car-tire-alert" @property - def state(self): + def native_value(self): """Return the state of the sensor.""" tire_pressure = self.data["status"]["tirePressure"]["frontRightTirePressurePsi"] return None if tire_pressure is None else round(tire_pressure) @@ -214,7 +214,7 @@ class MazdaRearLeftTirePressureSensor(MazdaEntity, SensorEntity): return f"{self.vin}_rear_left_tire_pressure" @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit of measurement.""" return PRESSURE_PSI @@ -224,7 +224,7 @@ class MazdaRearLeftTirePressureSensor(MazdaEntity, SensorEntity): return "mdi:car-tire-alert" @property - def state(self): + def native_value(self): """Return the state of the sensor.""" tire_pressure = self.data["status"]["tirePressure"]["rearLeftTirePressurePsi"] return None if tire_pressure is None else round(tire_pressure) @@ -245,7 +245,7 @@ class MazdaRearRightTirePressureSensor(MazdaEntity, SensorEntity): return f"{self.vin}_rear_right_tire_pressure" @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit of measurement.""" return PRESSURE_PSI @@ -255,7 +255,7 @@ class MazdaRearRightTirePressureSensor(MazdaEntity, SensorEntity): return "mdi:car-tire-alert" @property - def state(self): + def native_value(self): """Return the state of the sensor.""" tire_pressure = self.data["status"]["tirePressure"]["rearRightTirePressurePsi"] return None if tire_pressure is None else round(tire_pressure) diff --git a/homeassistant/components/melcloud/sensor.py b/homeassistant/components/melcloud/sensor.py index 6c303e8e3c3..12029127b84 100644 --- a/homeassistant/components/melcloud/sensor.py +++ b/homeassistant/components/melcloud/sensor.py @@ -41,7 +41,7 @@ ATA_SENSORS: tuple[MelcloudSensorEntityDescription, ...] = ( key="room_temperature", name="Room Temperature", icon="mdi:thermometer", - unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=TEMP_CELSIUS, device_class=DEVICE_CLASS_TEMPERATURE, value_fn=lambda x: x.device.room_temperature, enabled=lambda x: True, @@ -50,7 +50,7 @@ ATA_SENSORS: tuple[MelcloudSensorEntityDescription, ...] = ( key="energy", name="Energy", icon="mdi:factory", - unit_of_measurement=ENERGY_KILO_WATT_HOUR, + native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, device_class=DEVICE_CLASS_ENERGY, value_fn=lambda x: x.device.total_energy_consumed, enabled=lambda x: x.device.has_energy_consumed_meter, @@ -61,7 +61,7 @@ ATW_SENSORS: tuple[MelcloudSensorEntityDescription, ...] = ( key="outside_temperature", name="Outside Temperature", icon="mdi:thermometer", - unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=TEMP_CELSIUS, device_class=DEVICE_CLASS_TEMPERATURE, value_fn=lambda x: x.device.outside_temperature, enabled=lambda x: True, @@ -70,7 +70,7 @@ ATW_SENSORS: tuple[MelcloudSensorEntityDescription, ...] = ( key="tank_temperature", name="Tank Temperature", icon="mdi:thermometer", - unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=TEMP_CELSIUS, device_class=DEVICE_CLASS_TEMPERATURE, value_fn=lambda x: x.device.tank_temperature, enabled=lambda x: True, @@ -81,7 +81,7 @@ ATW_ZONE_SENSORS: tuple[MelcloudSensorEntityDescription, ...] = ( key="room_temperature", name="Room Temperature", icon="mdi:thermometer", - unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=TEMP_CELSIUS, device_class=DEVICE_CLASS_TEMPERATURE, value_fn=lambda zone: zone.room_temperature, enabled=lambda x: True, @@ -90,7 +90,7 @@ ATW_ZONE_SENSORS: tuple[MelcloudSensorEntityDescription, ...] = ( key="flow_temperature", name="Flow Temperature", icon="mdi:thermometer", - unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=TEMP_CELSIUS, device_class=DEVICE_CLASS_TEMPERATURE, value_fn=lambda zone: zone.flow_temperature, enabled=lambda x: True, @@ -99,7 +99,7 @@ ATW_ZONE_SENSORS: tuple[MelcloudSensorEntityDescription, ...] = ( key="return_temperature", name="Flow Return Temperature", icon="mdi:thermometer", - unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=TEMP_CELSIUS, device_class=DEVICE_CLASS_TEMPERATURE, value_fn=lambda zone: zone.return_temperature, enabled=lambda x: True, @@ -156,7 +156,7 @@ class MelDeviceSensor(SensorEntity): self._attr_last_reset = dt_util.utc_from_timestamp(0) @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return self.entity_description.value_fn(self._api) @@ -187,6 +187,6 @@ class AtwZoneSensor(MelDeviceSensor): self._attr_name = f"{api.name} {zone.name} {description.name}" @property - def state(self): + def native_value(self): """Return zone based state.""" return self.entity_description.value_fn(self._zone) diff --git a/homeassistant/components/meteo_france/sensor.py b/homeassistant/components/meteo_france/sensor.py index ed1978d160d..df006c78194 100644 --- a/homeassistant/components/meteo_france/sensor.py +++ b/homeassistant/components/meteo_france/sensor.py @@ -109,7 +109,7 @@ class MeteoFranceSensor(CoordinatorEntity, SensorEntity): } @property - def state(self): + def native_value(self): """Return the state.""" path = SENSOR_TYPES[self._type][ENTITY_API_DATA_PATH].split(":") data = getattr(self.coordinator.data, path[0]) @@ -135,7 +135,7 @@ class MeteoFranceSensor(CoordinatorEntity, SensorEntity): return value @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit of measurement.""" return SENSOR_TYPES[self._type][ENTITY_UNIT] @@ -164,7 +164,7 @@ class MeteoFranceRainSensor(MeteoFranceSensor): """Representation of a Meteo-France rain sensor.""" @property - def state(self): + def native_value(self): """Return the state.""" # search first cadran with rain next_rain = next( @@ -202,7 +202,7 @@ class MeteoFranceAlertSensor(MeteoFranceSensor): self._unique_id = self._name @property - def state(self): + def native_value(self): """Return the state.""" return get_warning_text_status_from_indice_color( self.coordinator.data.get_domain_max_color() diff --git a/homeassistant/components/meteoclimatic/sensor.py b/homeassistant/components/meteoclimatic/sensor.py index 101b889498d..b5a07ad06e6 100644 --- a/homeassistant/components/meteoclimatic/sensor.py +++ b/homeassistant/components/meteoclimatic/sensor.py @@ -51,7 +51,9 @@ class MeteoclimaticSensor(CoordinatorEntity, SensorEntity): f"{station.name} {SENSOR_TYPES[sensor_type][SENSOR_TYPE_NAME]}" ) self._attr_unique_id = f"{station.code}_{sensor_type}" - self._attr_unit_of_measurement = SENSOR_TYPES[sensor_type].get(SENSOR_TYPE_UNIT) + self._attr_native_unit_of_measurement = SENSOR_TYPES[sensor_type].get( + SENSOR_TYPE_UNIT + ) @property def device_info(self): @@ -65,7 +67,7 @@ class MeteoclimaticSensor(CoordinatorEntity, SensorEntity): } @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return ( getattr(self.coordinator.data["weather"], self._type) diff --git a/homeassistant/components/metoffice/sensor.py b/homeassistant/components/metoffice/sensor.py index 749282b1a21..4919e36bd58 100644 --- a/homeassistant/components/metoffice/sensor.py +++ b/homeassistant/components/metoffice/sensor.py @@ -42,7 +42,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( key="name", name="Station Name", device_class=None, - unit_of_measurement=None, + native_unit_of_measurement=None, icon="mdi:label-outline", entity_registry_enabled_default=False, ), @@ -50,7 +50,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( key="weather", name="Weather", device_class=None, - unit_of_measurement=None, + native_unit_of_measurement=None, icon="mdi:weather-sunny", # but will adapt to current conditions entity_registry_enabled_default=True, ), @@ -58,7 +58,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( key="temperature", name="Temperature", device_class=DEVICE_CLASS_TEMPERATURE, - unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=TEMP_CELSIUS, icon=None, entity_registry_enabled_default=True, ), @@ -66,7 +66,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( key="feels_like_temperature", name="Feels Like Temperature", device_class=DEVICE_CLASS_TEMPERATURE, - unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=TEMP_CELSIUS, icon=None, entity_registry_enabled_default=False, ), @@ -74,7 +74,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( key="wind_speed", name="Wind Speed", device_class=None, - unit_of_measurement=SPEED_MILES_PER_HOUR, + native_unit_of_measurement=SPEED_MILES_PER_HOUR, icon="mdi:weather-windy", entity_registry_enabled_default=True, ), @@ -82,7 +82,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( key="wind_direction", name="Wind Direction", device_class=None, - unit_of_measurement=None, + native_unit_of_measurement=None, icon="mdi:compass-outline", entity_registry_enabled_default=False, ), @@ -90,7 +90,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( key="wind_gust", name="Wind Gust", device_class=None, - unit_of_measurement=SPEED_MILES_PER_HOUR, + native_unit_of_measurement=SPEED_MILES_PER_HOUR, icon="mdi:weather-windy", entity_registry_enabled_default=False, ), @@ -98,7 +98,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( key="visibility", name="Visibility", device_class=None, - unit_of_measurement=None, + native_unit_of_measurement=None, icon="mdi:eye", entity_registry_enabled_default=False, ), @@ -106,7 +106,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( key="visibility_distance", name="Visibility Distance", device_class=None, - unit_of_measurement=LENGTH_KILOMETERS, + native_unit_of_measurement=LENGTH_KILOMETERS, icon="mdi:eye", entity_registry_enabled_default=False, ), @@ -114,7 +114,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( key="uv", name="UV Index", device_class=None, - unit_of_measurement=UV_INDEX, + native_unit_of_measurement=UV_INDEX, icon="mdi:weather-sunny-alert", entity_registry_enabled_default=True, ), @@ -122,7 +122,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( key="precipitation", name="Probability of Precipitation", device_class=None, - unit_of_measurement=PERCENTAGE, + native_unit_of_measurement=PERCENTAGE, icon="mdi:weather-rainy", entity_registry_enabled_default=True, ), @@ -130,7 +130,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( key="humidity", name="Humidity", device_class=DEVICE_CLASS_HUMIDITY, - unit_of_measurement=PERCENTAGE, + native_unit_of_measurement=PERCENTAGE, icon=None, entity_registry_enabled_default=False, ), @@ -189,7 +189,7 @@ class MetOfficeCurrentSensor(CoordinatorEntity, SensorEntity): self.use_3hourly = use_3hourly @property - def state(self): + def native_value(self): """Return the state of the sensor.""" value = None diff --git a/homeassistant/components/mfi/sensor.py b/homeassistant/components/mfi/sensor.py index fafaf53ff99..b27f719d974 100644 --- a/homeassistant/components/mfi/sensor.py +++ b/homeassistant/components/mfi/sensor.py @@ -88,7 +88,7 @@ class MfiSensor(SensorEntity): return self._port.label @property - def state(self): + def native_value(self): """Return the state of the sensor.""" try: tag = self._port.tag @@ -115,7 +115,7 @@ class MfiSensor(SensorEntity): return None @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit of measurement of this entity, if any.""" try: tag = self._port.tag diff --git a/homeassistant/components/mhz19/sensor.py b/homeassistant/components/mhz19/sensor.py index 63a1181f720..7d5d5eba183 100644 --- a/homeassistant/components/mhz19/sensor.py +++ b/homeassistant/components/mhz19/sensor.py @@ -90,12 +90,12 @@ class MHZ19Sensor(SensorEntity): return f"{self._name}: {SENSOR_TYPES[self._sensor_type][0]}" @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return self._ppm if self._sensor_type == SENSOR_CO2 else self._temperature @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/miflora/sensor.py b/homeassistant/components/miflora/sensor.py index a7aab41bea9..f712ffe6fe5 100644 --- a/homeassistant/components/miflora/sensor.py +++ b/homeassistant/components/miflora/sensor.py @@ -180,7 +180,7 @@ class MiFloraSensor(SensorEntity): return self._name @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return self._state @@ -207,7 +207,7 @@ class MiFloraSensor(SensorEntity): return STATE_CLASS_MEASUREMENT @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the units of measurement.""" return self._unit diff --git a/homeassistant/components/min_max/sensor.py b/homeassistant/components/min_max/sensor.py index d103ff8eaa6..e4b4cdf9922 100644 --- a/homeassistant/components/min_max/sensor.py +++ b/homeassistant/components/min_max/sensor.py @@ -172,7 +172,7 @@ class MinMaxSensor(SensorEntity): return self._name @property - def state(self): + def native_value(self): """Return the state of the sensor.""" if self._unit_of_measurement_mismatch: return None @@ -181,7 +181,7 @@ class MinMaxSensor(SensorEntity): ) @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit the value is expressed in.""" if self._unit_of_measurement_mismatch: return "ERR" diff --git a/homeassistant/components/minecraft_server/sensor.py b/homeassistant/components/minecraft_server/sensor.py index 651c2762c55..9f1c89f09c6 100644 --- a/homeassistant/components/minecraft_server/sensor.py +++ b/homeassistant/components/minecraft_server/sensor.py @@ -70,12 +70,12 @@ class MinecraftServerSensorEntity(MinecraftServerEntity, SensorEntity): return self._server.online @property - def state(self) -> Any: + def native_value(self) -> Any: """Return sensor state.""" return self._state @property - def unit_of_measurement(self) -> str: + def native_unit_of_measurement(self) -> str: """Return sensor measurement unit.""" return self._unit diff --git a/homeassistant/components/mitemp_bt/sensor.py b/homeassistant/components/mitemp_bt/sensor.py index 670a6daf3d3..732beb11b3a 100644 --- a/homeassistant/components/mitemp_bt/sensor.py +++ b/homeassistant/components/mitemp_bt/sensor.py @@ -127,12 +127,12 @@ class MiTempBtSensor(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 units of measurement.""" return self._unit diff --git a/homeassistant/components/mobile_app/sensor.py b/homeassistant/components/mobile_app/sensor.py index 7e3c1c13148..f6652f7f889 100644 --- a/homeassistant/components/mobile_app/sensor.py +++ b/homeassistant/components/mobile_app/sensor.py @@ -74,11 +74,11 @@ class MobileAppSensor(MobileAppEntity, SensorEntity): """Representation of an mobile app sensor.""" @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return self._config[ATTR_SENSOR_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._config.get(ATTR_SENSOR_UOM) diff --git a/homeassistant/components/modbus/sensor.py b/homeassistant/components/modbus/sensor.py index fee3f53667d..3165f416a6e 100644 --- a/homeassistant/components/modbus/sensor.py +++ b/homeassistant/components/modbus/sensor.py @@ -47,14 +47,14 @@ class ModbusRegisterSensor(BaseStructPlatform, RestoreEntity, SensorEntity): ) -> None: """Initialize the modbus register sensor.""" super().__init__(hub, entry) - self._attr_unit_of_measurement = entry.get(CONF_UNIT_OF_MEASUREMENT) + self._attr_native_unit_of_measurement = entry.get(CONF_UNIT_OF_MEASUREMENT) async def async_added_to_hass(self): """Handle entity which will be added.""" await self.async_base_added_to_hass() state = await self.async_get_last_state() if state: - self._attr_state = state.state + self._attr_native_value = state.state async def async_update(self, now=None): """Update the state of the sensor.""" @@ -68,6 +68,6 @@ class ModbusRegisterSensor(BaseStructPlatform, RestoreEntity, SensorEntity): self.async_write_ha_state() return - self._attr_state = self.unpack_structure_result(result.registers) + self._attr_native_value = self.unpack_structure_result(result.registers) self._attr_available = True self.async_write_ha_state() diff --git a/homeassistant/components/modem_callerid/sensor.py b/homeassistant/components/modem_callerid/sensor.py index 080e077a457..afbc09eb45c 100644 --- a/homeassistant/components/modem_callerid/sensor.py +++ b/homeassistant/components/modem_callerid/sensor.py @@ -75,7 +75,7 @@ class ModemCalleridSensor(SensorEntity): return ICON @property - def state(self): + def native_value(self): """Return the state of the device.""" return self._state diff --git a/homeassistant/components/modern_forms/sensor.py b/homeassistant/components/modern_forms/sensor.py index 01efe3f1d28..1e51ec9a1ae 100644 --- a/homeassistant/components/modern_forms/sensor.py +++ b/homeassistant/components/modern_forms/sensor.py @@ -73,7 +73,7 @@ class ModernFormsLightTimerRemainingTimeSensor(ModernFormsSensor): self._attr_device_class = DEVICE_CLASS_TIMESTAMP @property - def state(self) -> StateType: + def native_value(self) -> StateType: """Return the state of the sensor.""" sleep_time: datetime = dt_util.utc_from_timestamp( self.coordinator.data.state.light_sleep_timer @@ -103,7 +103,7 @@ class ModernFormsFanTimerRemainingTimeSensor(ModernFormsSensor): self._attr_device_class = DEVICE_CLASS_TIMESTAMP @property - def state(self) -> StateType: + def native_value(self) -> StateType: """Return the state of the sensor.""" sleep_time: datetime = dt_util.utc_from_timestamp( self.coordinator.data.state.fan_sleep_timer diff --git a/homeassistant/components/mold_indicator/sensor.py b/homeassistant/components/mold_indicator/sensor.py index 7bfa161f9ec..c57903ce5b7 100644 --- a/homeassistant/components/mold_indicator/sensor.py +++ b/homeassistant/components/mold_indicator/sensor.py @@ -359,12 +359,12 @@ class MoldIndicator(SensorEntity): return self._name @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit of measurement.""" return PERCENTAGE @property - def state(self): + def native_value(self): """Return the state of the entity.""" return self._state diff --git a/homeassistant/components/moon/sensor.py b/homeassistant/components/moon/sensor.py index 6213e218d24..223ee831779 100644 --- a/homeassistant/components/moon/sensor.py +++ b/homeassistant/components/moon/sensor.py @@ -60,7 +60,7 @@ class MoonSensor(SensorEntity): return "moon__phase" @property - def state(self): + def native_value(self): """Return the state of the device.""" if self._state == 0: return STATE_NEW_MOON diff --git a/homeassistant/components/motion_blinds/sensor.py b/homeassistant/components/motion_blinds/sensor.py index be88a099f25..9c6db5d88ec 100644 --- a/homeassistant/components/motion_blinds/sensor.py +++ b/homeassistant/components/motion_blinds/sensor.py @@ -47,7 +47,7 @@ class MotionBatterySensor(CoordinatorEntity, SensorEntity): """ _attr_device_class = DEVICE_CLASS_BATTERY - _attr_unit_of_measurement = PERCENTAGE + _attr_native_unit_of_measurement = PERCENTAGE def __init__(self, coordinator, blind): """Initialize the Motion Battery Sensor.""" @@ -70,7 +70,7 @@ class MotionBatterySensor(CoordinatorEntity, SensorEntity): return self.coordinator.data[self._blind.mac][ATTR_AVAILABLE] @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return self._blind.battery_level @@ -106,7 +106,7 @@ class MotionTDBUBatterySensor(MotionBatterySensor): self._attr_name = f"{blind.blind_type}-{motor}-battery-{blind.mac[12:]}" @property - def state(self): + def native_value(self): """Return the state of the sensor.""" if self._blind.battery_level is None: return None @@ -128,7 +128,7 @@ class MotionSignalStrengthSensor(CoordinatorEntity, SensorEntity): _attr_device_class = DEVICE_CLASS_SIGNAL_STRENGTH _attr_entity_registry_enabled_default = False - _attr_unit_of_measurement = SIGNAL_STRENGTH_DECIBELS_MILLIWATT + _attr_native_unit_of_measurement = SIGNAL_STRENGTH_DECIBELS_MILLIWATT def __init__(self, coordinator, device, device_type): """Initialize the Motion Signal Strength Sensor.""" @@ -162,7 +162,7 @@ class MotionSignalStrengthSensor(CoordinatorEntity, SensorEntity): ) @property - def state(self): + def native_value(self): """Return the state of the sensor.""" return self._device.RSSI diff --git a/homeassistant/components/mqtt/sensor.py b/homeassistant/components/mqtt/sensor.py index 239af7b450a..eac136d3f84 100644 --- a/homeassistant/components/mqtt/sensor.py +++ b/homeassistant/components/mqtt/sensor.py @@ -214,7 +214,7 @@ class MqttSensor(MqttEntity, SensorEntity): self.async_write_ha_state() @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit this state is expressed in.""" return self._config.get(CONF_UNIT_OF_MEASUREMENT) @@ -224,7 +224,7 @@ class MqttSensor(MqttEntity, SensorEntity): return self._config[CONF_FORCE_UPDATE] @property - def state(self): + def native_value(self): """Return the state of the entity.""" return self._state diff --git a/homeassistant/components/mqtt_room/sensor.py b/homeassistant/components/mqtt_room/sensor.py index b40d550abf6..479b02ebcbd 100644 --- a/homeassistant/components/mqtt_room/sensor.py +++ b/homeassistant/components/mqtt_room/sensor.py @@ -139,7 +139,7 @@ class MQTTRoomSensor(SensorEntity): return {ATTR_DISTANCE: self._distance} @property - def state(self): + def native_value(self): """Return the current room of the entity.""" return self._state diff --git a/homeassistant/components/mvglive/sensor.py b/homeassistant/components/mvglive/sensor.py index 953fe4c69a8..416ce21cbaf 100644 --- a/homeassistant/components/mvglive/sensor.py +++ b/homeassistant/components/mvglive/sensor.py @@ -108,7 +108,7 @@ class MVGLiveSensor(SensorEntity): return self._station @property - def state(self): + def native_value(self): """Return the next departure time.""" return self._state @@ -128,7 +128,7 @@ class MVGLiveSensor(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/mychevy/sensor.py b/homeassistant/components/mychevy/sensor.py index 18b5e95d838..1a5613d8864 100644 --- a/homeassistant/components/mychevy/sensor.py +++ b/homeassistant/components/mychevy/sensor.py @@ -98,7 +98,7 @@ class MyChevyStatus(SensorEntity): return self._name @property - def state(self): + def native_value(self): """Return the state.""" return self._state @@ -166,7 +166,7 @@ class EVSensor(SensorEntity): self.async_write_ha_state() @property - def state(self): + def native_value(self): """Return the state.""" return self._state @@ -176,7 +176,7 @@ class EVSensor(SensorEntity): return self._state_attributes @property - def unit_of_measurement(self): + def native_unit_of_measurement(self): """Return the unit of measurement the state is expressed in.""" return self._unit_of_measurement diff --git a/homeassistant/components/mysensors/sensor.py b/homeassistant/components/mysensors/sensor.py index c7755b13512..bb56770fd0c 100644 --- a/homeassistant/components/mysensors/sensor.py +++ b/homeassistant/components/mysensors/sensor.py @@ -147,8 +147,8 @@ class MySensorsSensor(mysensors.device.MySensorsEntity, SensorEntity): return True @property - def state(self) -> str | None: - """Return the state of this entity.""" + def native_value(self) -> str | None: + """Return the state of the device.""" return self._values.get(self.value_type) @property @@ -176,7 +176,7 @@ class MySensorsSensor(mysensors.device.MySensorsEntity, SensorEntity): return self._get_sensor_type()[3] @property - def unit_of_measurement(self) -> str | None: + def native_unit_of_measurement(self) -> str | None: """Return the unit of measurement of this entity.""" set_req = self.gateway.const.SetReq if ( diff --git a/tests/components/litterrobot/test_sensor.py b/tests/components/litterrobot/test_sensor.py index a5f5b955882..dbc8c39790c 100644 --- a/tests/components/litterrobot/test_sensor.py +++ b/tests/components/litterrobot/test_sensor.py @@ -26,6 +26,7 @@ async def test_sleep_time_sensor_with_none_state(hass): sensor = LitterRobotSleepTimeSensor( robot, "Sleep Mode Start Time", Mock(), "sleep_mode_start_time" ) + sensor.hass = hass assert sensor assert sensor.state is None diff --git a/tests/components/mfi/test_sensor.py b/tests/components/mfi/test_sensor.py index 1f5cc5fd04f..4032e29b743 100644 --- a/tests/components/mfi/test_sensor.py +++ b/tests/components/mfi/test_sensor.py @@ -121,7 +121,9 @@ def port_fixture(): @pytest.fixture(name="sensor") def sensor_fixture(hass, port): """Sensor fixture.""" - return mfi.MfiSensor(port, hass) + sensor = mfi.MfiSensor(port, hass) + sensor.hass = hass + return sensor async def test_name(port, sensor): diff --git a/tests/components/mhz19/test_sensor.py b/tests/components/mhz19/test_sensor.py index e827b5dfbd2..26e9441f9fc 100644 --- a/tests/components/mhz19/test_sensor.py +++ b/tests/components/mhz19/test_sensor.py @@ -83,10 +83,11 @@ async def aiohttp_client_update_good_read(mock_function): @patch("pmsensor.co2sensor.read_mh_z19_with_temperature", return_value=(1000, 24)) -async def test_co2_sensor(mock_function): +async def test_co2_sensor(mock_function, hass): """Test CO2 sensor.""" client = mhz19.MHZClient(co2sensor, "test.serial") sensor = mhz19.MHZ19Sensor(client, mhz19.SENSOR_CO2, None, "name") + sensor.hass = hass sensor.update() assert sensor.name == "name: CO2" @@ -97,10 +98,11 @@ async def test_co2_sensor(mock_function): @patch("pmsensor.co2sensor.read_mh_z19_with_temperature", return_value=(1000, 24)) -async def test_temperature_sensor(mock_function): +async def test_temperature_sensor(mock_function, hass): """Test temperature sensor.""" client = mhz19.MHZClient(co2sensor, "test.serial") sensor = mhz19.MHZ19Sensor(client, mhz19.SENSOR_TEMPERATURE, None, "name") + sensor.hass = hass sensor.update() assert sensor.name == "name: Temperature" @@ -111,12 +113,13 @@ async def test_temperature_sensor(mock_function): @patch("pmsensor.co2sensor.read_mh_z19_with_temperature", return_value=(1000, 24)) -async def test_temperature_sensor_f(mock_function): +async def test_temperature_sensor_f(mock_function, hass): """Test temperature sensor.""" client = mhz19.MHZClient(co2sensor, "test.serial") sensor = mhz19.MHZ19Sensor( client, mhz19.SENSOR_TEMPERATURE, TEMP_FAHRENHEIT, "name" ) + sensor.hass = hass sensor.update() assert sensor.state == 75.2