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

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

* Fix litterrobot sensor

* Fix tests
This commit is contained in:
Erik Montnemery 2021-08-11 21:17:47 +02:00 committed by GitHub
parent ae507aeed1
commit 2720ba2753
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
70 changed files with 195 additions and 183 deletions

View File

@ -86,7 +86,7 @@ class IamMeter(CoordinatorEntity, SensorEntity):
self.dev_name = dev_name self.dev_name = dev_name
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self.coordinator.data.data[self.sensor_name] return self.coordinator.data.data[self.sensor_name]
@ -106,6 +106,6 @@ class IamMeter(CoordinatorEntity, SensorEntity):
return "mdi:flash" return "mdi:flash"
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement.""" """Return the unit of measurement."""
return self.unit return self.unit

View File

@ -31,7 +31,7 @@ class HassAqualinkSensor(AqualinkEntity, SensorEntity):
return self.dev.label return self.dev.label
@property @property
def unit_of_measurement(self) -> str | None: def native_unit_of_measurement(self) -> str | None:
"""Return the measurement unit for the sensor.""" """Return the measurement unit for the sensor."""
if self.dev.name.endswith("_temp"): if self.dev.name.endswith("_temp"):
if self.dev.system.temp_unit == "F": if self.dev.system.temp_unit == "F":
@ -40,7 +40,7 @@ class HassAqualinkSensor(AqualinkEntity, SensorEntity):
return None return None
@property @property
def state(self) -> str | None: def native_value(self) -> str | None:
"""Return the state of the sensor.""" """Return the state of the sensor."""
if self.dev.state == "": if self.dev.state == "":
return None return None

View File

@ -54,7 +54,7 @@ class IcloudDeviceBatterySensor(SensorEntity):
"""Representation of a iCloud device battery sensor.""" """Representation of a iCloud device battery sensor."""
_attr_device_class = DEVICE_CLASS_BATTERY _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: def __init__(self, account: IcloudAccount, device: IcloudDevice) -> None:
"""Initialize the battery sensor.""" """Initialize the battery sensor."""
@ -73,7 +73,7 @@ class IcloudDeviceBatterySensor(SensorEntity):
return f"{self._device.name} battery state" return f"{self._device.name} battery state"
@property @property
def state(self) -> int: def native_value(self) -> int:
"""Battery state percentage.""" """Battery state percentage."""
return self._device.battery_level return self._device.battery_level

View File

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

View File

@ -95,7 +95,7 @@ class ImapSensor(SensorEntity):
return ICON return ICON
@property @property
def state(self): def native_value(self):
"""Return the number of emails found.""" """Return the number of emails found."""
return self._email_count return self._email_count

View File

@ -165,7 +165,7 @@ class EmailContentSensor(SensorEntity):
return self._name return self._name
@property @property
def state(self): def native_value(self):
"""Return the current email state.""" """Return the current email state."""
return self._message return self._message

View File

@ -59,7 +59,7 @@ class IncomfortSensor(IncomfortChild, SensorEntity):
self._unit_of_measurement = None self._unit_of_measurement = None
@property @property
def state(self) -> str | None: def native_value(self) -> str | None:
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._heater.status[self._state_attr] return self._heater.status[self._state_attr]
@ -69,7 +69,7 @@ class IncomfortSensor(IncomfortChild, SensorEntity):
return self._device_class return self._device_class
@property @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 the unit of measurement of the sensor."""
return self._unit_of_measurement return self._unit_of_measurement

View File

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

View File

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

View File

@ -14,7 +14,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription( SensorEntityDescription(
key="level", key="level",
name="Battery Level", name="Battery Level",
unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
), ),
SensorEntityDescription( SensorEntityDescription(
key="state", key="state",
@ -114,12 +114,16 @@ class IOSSensor(SensorEntity):
def _update(self, device): def _update(self, device):
"""Get the latest state of the sensor.""" """Get the latest state of the sensor."""
self._device = device 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() self.async_write_ha_state()
async def async_added_to_hass(self) -> None: async def async_added_to_hass(self) -> None:
"""Added to hass so need to register to dispatch.""" """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] device_id = self._device[ios.ATTR_DEVICE_ID]
self.async_on_remove( self.async_on_remove(
async_dispatcher_connect(self.hass, f"{DOMAIN}.{device_id}", self._update) async_dispatcher_connect(self.hass, f"{DOMAIN}.{device_id}", self._update)

View File

@ -47,12 +47,12 @@ class IotaBalanceSensor(IotaDevice, SensorEntity):
return f"{self._name} Balance" return f"{self._name} Balance"
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement.""" """Return the unit of measurement."""
return "IOTA" return "IOTA"
@ -81,7 +81,7 @@ class IotaNodeSensor(IotaDevice, SensorEntity):
return "IOTA Node" return "IOTA Node"
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state

View File

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

View File

@ -72,7 +72,7 @@ class IPPSensor(IPPEntity, SensorEntity):
"""Initialize IPP sensor.""" """Initialize IPP sensor."""
self._key = key self._key = key
self._attr_unique_id = f"{unique_id}_{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__( super().__init__(
entry_id=entry_id, entry_id=entry_id,
@ -123,7 +123,7 @@ class IPPMarkerSensor(IPPSensor):
} }
@property @property
def state(self) -> int | None: def native_value(self) -> int | None:
"""Return the state of the sensor.""" """Return the state of the sensor."""
level = self.coordinator.data.markers[self.marker_index].level level = self.coordinator.data.markers[self.marker_index].level
@ -164,7 +164,7 @@ class IPPPrinterSensor(IPPSensor):
} }
@property @property
def state(self) -> str: def native_value(self) -> str:
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self.coordinator.data.state.printer_state return self.coordinator.data.state.printer_state
@ -189,7 +189,7 @@ class IPPUptimeSensor(IPPSensor):
) )
@property @property
def state(self) -> str: def native_value(self) -> str:
"""Return the state of the sensor.""" """Return the state of the sensor."""
uptime = utcnow() - timedelta(seconds=self.coordinator.data.info.uptime) uptime = utcnow() - timedelta(seconds=self.coordinator.data.info.uptime)
return uptime.replace(microsecond=0).isoformat() return uptime.replace(microsecond=0).isoformat()

View File

@ -109,7 +109,7 @@ class IQVIAEntity(CoordinatorEntity, SensorEntity):
self._attr_icon = icon self._attr_icon = icon
self._attr_name = name self._attr_name = name
self._attr_unique_id = f"{entry.data[CONF_ZIP_CODE]}_{sensor_type}" 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._entry = entry
self._type = sensor_type self._type = sensor_type

View File

@ -120,7 +120,7 @@ class ForecastSensor(IQVIAEntity):
if i["minimum"] <= average <= i["maximum"] if i["minimum"] <= average <= i["maximum"]
] ]
self._attr_state = average self._attr_native_value = average
self._attr_extra_state_attributes.update( self._attr_extra_state_attributes.update(
{ {
ATTR_CITY: data["City"].title(), ATTR_CITY: data["City"].title(),
@ -213,4 +213,4 @@ class IndexSensor(IQVIAEntity):
f"{attrs['Name'].lower()}_index" f"{attrs['Name'].lower()}_index"
] = attrs["Index"] ] = attrs["Index"]
self._attr_state = period["Index"] self._attr_native_value = period["Index"]

View File

@ -83,7 +83,7 @@ class IrishRailTransportSensor(SensorEntity):
return self._name return self._name
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state
@ -114,7 +114,7 @@ class IrishRailTransportSensor(SensorEntity):
} }
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit this state is expressed in.""" """Return the unit this state is expressed in."""
return TIME_MINUTES return TIME_MINUTES

View File

@ -43,7 +43,7 @@ class IslamicPrayerTimeSensor(SensorEntity):
return self.sensor_type return self.sensor_type
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return ( return (
self.client.prayer_times_info.get(self.sensor_type) self.client.prayer_times_info.get(self.sensor_type)

View File

@ -67,7 +67,7 @@ class ISYSensorEntity(ISYNodeEntity, SensorEntity):
return UOM_FRIENDLY_NAME.get(uom) return UOM_FRIENDLY_NAME.get(uom)
@property @property
def state(self) -> str: def native_value(self) -> str:
"""Get the state of the ISY994 sensor device.""" """Get the state of the ISY994 sensor device."""
value = self._node.status value = self._node.status
if value == ISY_VALUE_UNKNOWN: if value == ISY_VALUE_UNKNOWN:
@ -97,7 +97,7 @@ class ISYSensorEntity(ISYNodeEntity, SensorEntity):
return value return value
@property @property
def unit_of_measurement(self) -> str: def native_unit_of_measurement(self) -> str:
"""Get the Home Assistant unit of measurement for the device.""" """Get the Home Assistant unit of measurement for the device."""
raw_units = self.raw_unit_of_measurement raw_units = self.raw_unit_of_measurement
# Check if this is a known index pair UOM # Check if this is a known index pair UOM
@ -117,7 +117,7 @@ class ISYSensorVariableEntity(ISYEntity, SensorEntity):
self._name = vname self._name = vname
@property @property
def state(self): def native_value(self):
"""Return the state of the variable.""" """Return the state of the variable."""
return convert_isy_value_to_hass(self._node.status, "", self._node.prec) return convert_isy_value_to_hass(self._node.status, "", self._node.prec)

View File

@ -50,7 +50,7 @@ class JewishCalendarSensor(SensorEntity):
self._holiday_attrs = {} self._holiday_attrs = {}
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
if isinstance(self._state, datetime): if isinstance(self._state, datetime):
return self._state.isoformat() return self._state.isoformat()
@ -134,7 +134,7 @@ class JewishCalendarTimeSensor(JewishCalendarSensor):
_attr_device_class = DEVICE_CLASS_TIMESTAMP _attr_device_class = DEVICE_CLASS_TIMESTAMP
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
if self._state is None: if self._state is None:
return None return None

View File

@ -31,40 +31,40 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription( SensorEntityDescription(
key="temperature", key="temperature",
name="Temperature", name="Temperature",
unit_of_measurement=TEMP_CELSIUS, native_unit_of_measurement=TEMP_CELSIUS,
device_class=DEVICE_CLASS_TEMPERATURE, device_class=DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
SensorEntityDescription( SensorEntityDescription(
key="voltage", key="voltage",
name="Voltage", name="Voltage",
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
device_class=DEVICE_CLASS_VOLTAGE, device_class=DEVICE_CLASS_VOLTAGE,
), ),
SensorEntityDescription( SensorEntityDescription(
key="amps", key="amps",
name="Amps", name="Amps",
unit_of_measurement=ELECTRIC_CURRENT_AMPERE, native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
device_class=DEVICE_CLASS_CURRENT, device_class=DEVICE_CLASS_CURRENT,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
SensorEntityDescription( SensorEntityDescription(
key="watts", key="watts",
name="Watts", name="Watts",
unit_of_measurement=POWER_WATT, native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER, device_class=DEVICE_CLASS_POWER,
state_class=STATE_CLASS_MEASUREMENT, state_class=STATE_CLASS_MEASUREMENT,
), ),
SensorEntityDescription( SensorEntityDescription(
key="charge_time", key="charge_time",
name="Charge time", name="Charge time",
unit_of_measurement=TIME_SECONDS, native_unit_of_measurement=TIME_SECONDS,
icon="mdi:timer-outline", icon="mdi:timer-outline",
), ),
SensorEntityDescription( SensorEntityDescription(
key="energy_added", key="energy_added",
name="Energy added", name="Energy added",
unit_of_measurement=ENERGY_WATT_HOUR, native_unit_of_measurement=ENERGY_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY, device_class=DEVICE_CLASS_ENERGY,
), ),
) )
@ -110,6 +110,6 @@ class JuiceNetSensorDevice(JuiceNetDevice, SensorEntity):
return icon return icon
@property @property
def state(self): def native_value(self):
"""Return the state.""" """Return the state."""
return getattr(self.device, self.entity_description.key, None) return getattr(self.device, self.entity_description.key, None)

View File

@ -70,7 +70,7 @@ class KaiterraSensor(SensorEntity):
return self._name return self._name
@property @property
def state(self): def native_value(self):
"""Return the state.""" """Return the state."""
return self._sensor.get("value") return self._sensor.get("value")
@ -80,7 +80,7 @@ class KaiterraSensor(SensorEntity):
return f"{self._device_id}_{self._kind}" return f"{self._device_id}_{self._kind}"
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit the value is expressed in.""" """Return the unit the value is expressed in."""
if not self._sensor.get("units"): if not self._sensor.get("units"):
return None return None

View File

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

View File

@ -50,7 +50,7 @@ class KiraReceiver(SensorEntity):
return ICON return ICON
@property @property
def state(self): def native_value(self):
"""Return the state of the receiver.""" """Return the state of the receiver."""
return self._state return self._state

View File

@ -62,11 +62,11 @@ class KNXSensor(KnxEntity, SensorEntity):
) )
self._attr_force_update = self._device.always_callback self._attr_force_update = self._device.always_callback
self._attr_unique_id = str(self._device.sensor_value.group_address_state) 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) self._attr_state_class = config.get(SensorSchema.CONF_STATE_CLASS)
@property @property
def state(self) -> StateType: def native_value(self) -> StateType:
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._device.resolve_state() return self._device.resolve_state()

View File

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

View File

@ -169,7 +169,7 @@ class PlenticoreDataSensor(CoordinatorEntity, SensorEntity):
return f"{self.platform_name} {self._sensor_name}" return f"{self.platform_name} {self._sensor_name}"
@property @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 the unit of this Sensor Entity or None."""
return self._sensor_data.get(ATTR_UNIT_OF_MEASUREMENT) 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) return self._sensor_data.get(ATTR_LAST_RESET)
@property @property
def state(self) -> Any | None: def native_value(self) -> Any | None:
"""Return the state of the sensor.""" """Return the state of the sensor."""
if self.coordinator.data is None: if self.coordinator.data is None:
# None is translated to STATE_UNKNOWN # None is translated to STATE_UNKNOWN

View File

@ -124,7 +124,7 @@ class KrakenSensor(CoordinatorEntity, SensorEntity):
return self._name.lower() return self._name.lower()
@property @property
def state(self) -> StateType: def native_value(self) -> StateType:
"""Return the state.""" """Return the state."""
return self._state return self._state
@ -229,7 +229,7 @@ class KrakenSensor(CoordinatorEntity, SensorEntity):
return "mdi:cash" return "mdi:cash"
@property @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 the unit the value is expressed in."""
if "number_of" not in self._sensor_type: if "number_of" not in self._sensor_type:
return self._unit_of_measurement return self._unit_of_measurement

View File

@ -94,13 +94,13 @@ class KWBSensor(SensorEntity):
return self._sensor.available return self._sensor.available
@property @property
def state(self): def native_value(self):
"""Return the state of value.""" """Return the state of value."""
if self._sensor.value is not None and self._sensor.available: if self._sensor.value is not None and self._sensor.available:
return self._sensor.value return self._sensor.value
return None return None
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any.""" """Return the unit of measurement of this entity, if any."""
return self._sensor.unit_of_measurement return self._sensor.unit_of_measurement

View File

@ -176,10 +176,10 @@ class LaCrosseTemperature(LaCrosseSensor):
"""Implementation of a Lacrosse temperature sensor.""" """Implementation of a Lacrosse temperature sensor."""
_attr_device_class = DEVICE_CLASS_TEMPERATURE _attr_device_class = DEVICE_CLASS_TEMPERATURE
_attr_unit_of_measurement = TEMP_CELSIUS _attr_native_unit_of_measurement = TEMP_CELSIUS
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._temperature return self._temperature
@ -187,11 +187,11 @@ class LaCrosseTemperature(LaCrosseSensor):
class LaCrosseHumidity(LaCrosseSensor): class LaCrosseHumidity(LaCrosseSensor):
"""Implementation of a Lacrosse humidity sensor.""" """Implementation of a Lacrosse humidity sensor."""
_attr_unit_of_measurement = PERCENTAGE _attr_native_unit_of_measurement = PERCENTAGE
_attr_icon = "mdi:water-percent" _attr_icon = "mdi:water-percent"
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._humidity return self._humidity
@ -200,7 +200,7 @@ class LaCrosseBattery(LaCrosseSensor):
"""Implementation of a Lacrosse battery sensor.""" """Implementation of a Lacrosse battery sensor."""
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
if self._low_battery is None: if self._low_battery is None:
return None return None

View File

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

View File

@ -59,7 +59,7 @@ class LaunchLibrarySensor(SensorEntity):
else: else:
if next_launch := next((launch for launch in launches), None): if next_launch := next((launch for launch in launches), None):
self._attr_available = True self._attr_available = True
self._attr_state = next_launch.name self._attr_native_value = next_launch.name
self._attr_extra_state_attributes = { self._attr_extra_state_attributes = {
ATTR_LAUNCH_TIME: next_launch.net, ATTR_LAUNCH_TIME: next_launch.net,
ATTR_AGENCY: next_launch.launch_service_provider.name, ATTR_AGENCY: next_launch.launch_service_provider.name,

View File

@ -93,12 +93,12 @@ class LcnVariableSensor(LcnEntity, SensorEntity):
await self.device_connection.cancel_status_request_handler(self.variable) await self.device_connection.cancel_status_request_handler(self.variable)
@property @property
def state(self) -> str | None: def native_value(self) -> str | None:
"""Return the state of the entity.""" """Return the state of the entity."""
return self._value return self._value
@property @property
def unit_of_measurement(self) -> str: def native_unit_of_measurement(self) -> str:
"""Return the unit of measurement of this entity, if any.""" """Return the unit of measurement of this entity, if any."""
return cast(str, self.unit.value) return cast(str, self.unit.value)
@ -145,7 +145,7 @@ class LcnLedLogicSensor(LcnEntity, SensorEntity):
await self.device_connection.cancel_status_request_handler(self.source) await self.device_connection.cancel_status_request_handler(self.source)
@property @property
def state(self) -> str | None: def native_value(self) -> str | None:
"""Return the state of the entity.""" """Return the state of the entity."""
return self._value return self._value

View File

@ -26,7 +26,7 @@ class LightwaveBattery(SensorEntity):
"""Lightwave TRV Battery.""" """Lightwave TRV Battery."""
_attr_device_class = DEVICE_CLASS_BATTERY _attr_device_class = DEVICE_CLASS_BATTERY
_attr_unit_of_measurement = PERCENTAGE _attr_native_unit_of_measurement = PERCENTAGE
_attr_state_class = STATE_CLASS_MEASUREMENT _attr_state_class = STATE_CLASS_MEASUREMENT
def __init__(self, name, lwlink, serial): def __init__(self, name, lwlink, serial):
@ -43,7 +43,7 @@ class LightwaveBattery(SensorEntity):
return self._name return self._name
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state

View File

@ -90,12 +90,12 @@ class LinuxBatterySensor(SensorEntity):
return DEVICE_CLASS_BATTERY return DEVICE_CLASS_BATTERY
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._battery_stat.capacity return self._battery_stat.capacity
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit the value is expressed in.""" """Return the unit the value is expressed in."""
return PERCENTAGE return PERCENTAGE

View File

@ -36,7 +36,7 @@ class LitterRobotPropertySensor(LitterRobotEntity, SensorEntity):
self.sensor_attribute = sensor_attribute self.sensor_attribute = sensor_attribute
@property @property
def state(self) -> str: def native_value(self) -> str:
"""Return the state.""" """Return the state."""
return getattr(self.robot, self.sensor_attribute) return getattr(self.robot, self.sensor_attribute)
@ -45,7 +45,7 @@ class LitterRobotWasteSensor(LitterRobotPropertySensor):
"""Litter-Robot waste sensor.""" """Litter-Robot waste sensor."""
@property @property
def unit_of_measurement(self) -> str: def native_unit_of_measurement(self) -> str:
"""Return unit of measurement.""" """Return unit of measurement."""
return PERCENTAGE return PERCENTAGE
@ -59,10 +59,10 @@ class LitterRobotSleepTimeSensor(LitterRobotPropertySensor):
"""Litter-Robot sleep time sensor.""" """Litter-Robot sleep time sensor."""
@property @property
def state(self) -> str | None: def native_value(self) -> str | None:
"""Return the state.""" """Return the state."""
if self.robot.sleep_mode_enabled: if self.robot.sleep_mode_enabled:
return super().state.isoformat() return super().native_value.isoformat()
return None return None
@property @property

View File

@ -33,6 +33,6 @@ class IPSensor(SensorEntity):
async def async_update(self) -> None: async def async_update(self) -> None:
"""Fetch new state data for the sensor.""" """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 self.hass, target_ip=PUBLIC_TARGET_IP
) )

View File

@ -67,7 +67,7 @@ class LogiSensor(SensorEntity):
return self._name return self._name
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state
@ -112,7 +112,7 @@ class LogiSensor(SensorEntity):
return self._icon return self._icon
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the units of measurement.""" """Return the units of measurement."""
return SENSOR_TYPES.get(self._sensor_type)[1] return SENSOR_TYPES.get(self._sensor_type)[1]

View File

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

View File

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

View File

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

View File

@ -73,7 +73,7 @@ class LuftdatenSensor(SensorEntity):
return self._icon return self._icon
@property @property
def state(self): def native_value(self):
"""Return the state of the device.""" """Return the state of the device."""
if self._data is not None: if self._data is not None:
try: try:
@ -82,7 +82,7 @@ class LuftdatenSensor(SensorEntity):
return None return None
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any.""" """Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement return self._unit_of_measurement

View File

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

View File

@ -94,7 +94,7 @@ class LyricSensor(LyricDeviceEntity, SensorEntity):
return self._device_class return self._device_class
@property @property
def unit_of_measurement(self) -> str: def native_unit_of_measurement(self) -> str:
"""Return the unit this state is expressed in.""" """Return the unit this state is expressed in."""
return self._unit_of_measurement return self._unit_of_measurement
@ -123,7 +123,7 @@ class LyricIndoorTemperatureSensor(LyricSensor):
) )
@property @property
def state(self) -> str: def native_value(self) -> str:
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self.device.indoorTemperature return self.device.indoorTemperature
@ -152,7 +152,7 @@ class LyricOutdoorTemperatureSensor(LyricSensor):
) )
@property @property
def state(self) -> str: def native_value(self) -> str:
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self.device.outdoorTemperature return self.device.outdoorTemperature
@ -181,7 +181,7 @@ class LyricOutdoorHumiditySensor(LyricSensor):
) )
@property @property
def state(self) -> str: def native_value(self) -> str:
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self.device.displayedOutdoorHumidity return self.device.displayedOutdoorHumidity
@ -209,7 +209,7 @@ class LyricNextPeriodSensor(LyricSensor):
) )
@property @property
def state(self) -> datetime: def native_value(self) -> datetime:
"""Return the state of the sensor.""" """Return the state of the sensor."""
device = self.device device = self.device
time = dt_util.parse_time(device.changeableValues.nextPeriodTime) time = dt_util.parse_time(device.changeableValues.nextPeriodTime)
@ -242,7 +242,7 @@ class LyricSetpointStatusSensor(LyricSensor):
) )
@property @property
def state(self) -> str: def native_value(self) -> str:
"""Return the state of the sensor.""" """Return the state of the sensor."""
device = self.device device = self.device
if device.changeableValues.thermostatSetpointStatus == PRESET_HOLD_UNTIL: if device.changeableValues.thermostatSetpointStatus == PRESET_HOLD_UNTIL:

View File

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

View File

@ -46,7 +46,7 @@ class MazdaFuelRemainingSensor(MazdaEntity, SensorEntity):
return f"{self.vin}_fuel_remaining_percentage" return f"{self.vin}_fuel_remaining_percentage"
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement.""" """Return the unit of measurement."""
return PERCENTAGE return PERCENTAGE
@ -56,7 +56,7 @@ class MazdaFuelRemainingSensor(MazdaEntity, SensorEntity):
return "mdi:gas-station" return "mdi:gas-station"
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self.data["status"]["fuelRemainingPercent"] return self.data["status"]["fuelRemainingPercent"]
@ -76,7 +76,7 @@ class MazdaFuelDistanceSensor(MazdaEntity, SensorEntity):
return f"{self.vin}_fuel_distance_remaining" return f"{self.vin}_fuel_distance_remaining"
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement.""" """Return the unit of measurement."""
if self.hass.config.units.name == CONF_UNIT_SYSTEM_IMPERIAL: if self.hass.config.units.name == CONF_UNIT_SYSTEM_IMPERIAL:
return LENGTH_MILES return LENGTH_MILES
@ -88,7 +88,7 @@ class MazdaFuelDistanceSensor(MazdaEntity, SensorEntity):
return "mdi:gas-station" return "mdi:gas-station"
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
fuel_distance_km = self.data["status"]["fuelDistanceRemainingKm"] fuel_distance_km = self.data["status"]["fuelDistanceRemainingKm"]
return ( return (
@ -115,7 +115,7 @@ class MazdaOdometerSensor(MazdaEntity, SensorEntity):
return f"{self.vin}_odometer" return f"{self.vin}_odometer"
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement.""" """Return the unit of measurement."""
if self.hass.config.units.name == CONF_UNIT_SYSTEM_IMPERIAL: if self.hass.config.units.name == CONF_UNIT_SYSTEM_IMPERIAL:
return LENGTH_MILES return LENGTH_MILES
@ -127,7 +127,7 @@ class MazdaOdometerSensor(MazdaEntity, SensorEntity):
return "mdi:speedometer" return "mdi:speedometer"
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
odometer_km = self.data["status"]["odometerKm"] odometer_km = self.data["status"]["odometerKm"]
return ( return (
@ -152,7 +152,7 @@ class MazdaFrontLeftTirePressureSensor(MazdaEntity, SensorEntity):
return f"{self.vin}_front_left_tire_pressure" return f"{self.vin}_front_left_tire_pressure"
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement.""" """Return the unit of measurement."""
return PRESSURE_PSI return PRESSURE_PSI
@ -162,7 +162,7 @@ class MazdaFrontLeftTirePressureSensor(MazdaEntity, SensorEntity):
return "mdi:car-tire-alert" return "mdi:car-tire-alert"
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
tire_pressure = self.data["status"]["tirePressure"]["frontLeftTirePressurePsi"] tire_pressure = self.data["status"]["tirePressure"]["frontLeftTirePressurePsi"]
return None if tire_pressure is None else round(tire_pressure) 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" return f"{self.vin}_front_right_tire_pressure"
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement.""" """Return the unit of measurement."""
return PRESSURE_PSI return PRESSURE_PSI
@ -193,7 +193,7 @@ class MazdaFrontRightTirePressureSensor(MazdaEntity, SensorEntity):
return "mdi:car-tire-alert" return "mdi:car-tire-alert"
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
tire_pressure = self.data["status"]["tirePressure"]["frontRightTirePressurePsi"] tire_pressure = self.data["status"]["tirePressure"]["frontRightTirePressurePsi"]
return None if tire_pressure is None else round(tire_pressure) 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" return f"{self.vin}_rear_left_tire_pressure"
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement.""" """Return the unit of measurement."""
return PRESSURE_PSI return PRESSURE_PSI
@ -224,7 +224,7 @@ class MazdaRearLeftTirePressureSensor(MazdaEntity, SensorEntity):
return "mdi:car-tire-alert" return "mdi:car-tire-alert"
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
tire_pressure = self.data["status"]["tirePressure"]["rearLeftTirePressurePsi"] tire_pressure = self.data["status"]["tirePressure"]["rearLeftTirePressurePsi"]
return None if tire_pressure is None else round(tire_pressure) 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" return f"{self.vin}_rear_right_tire_pressure"
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement.""" """Return the unit of measurement."""
return PRESSURE_PSI return PRESSURE_PSI
@ -255,7 +255,7 @@ class MazdaRearRightTirePressureSensor(MazdaEntity, SensorEntity):
return "mdi:car-tire-alert" return "mdi:car-tire-alert"
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
tire_pressure = self.data["status"]["tirePressure"]["rearRightTirePressurePsi"] tire_pressure = self.data["status"]["tirePressure"]["rearRightTirePressurePsi"]
return None if tire_pressure is None else round(tire_pressure) return None if tire_pressure is None else round(tire_pressure)

View File

@ -41,7 +41,7 @@ ATA_SENSORS: tuple[MelcloudSensorEntityDescription, ...] = (
key="room_temperature", key="room_temperature",
name="Room Temperature", name="Room Temperature",
icon="mdi:thermometer", icon="mdi:thermometer",
unit_of_measurement=TEMP_CELSIUS, native_unit_of_measurement=TEMP_CELSIUS,
device_class=DEVICE_CLASS_TEMPERATURE, device_class=DEVICE_CLASS_TEMPERATURE,
value_fn=lambda x: x.device.room_temperature, value_fn=lambda x: x.device.room_temperature,
enabled=lambda x: True, enabled=lambda x: True,
@ -50,7 +50,7 @@ ATA_SENSORS: tuple[MelcloudSensorEntityDescription, ...] = (
key="energy", key="energy",
name="Energy", name="Energy",
icon="mdi:factory", icon="mdi:factory",
unit_of_measurement=ENERGY_KILO_WATT_HOUR, native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY, device_class=DEVICE_CLASS_ENERGY,
value_fn=lambda x: x.device.total_energy_consumed, value_fn=lambda x: x.device.total_energy_consumed,
enabled=lambda x: x.device.has_energy_consumed_meter, enabled=lambda x: x.device.has_energy_consumed_meter,
@ -61,7 +61,7 @@ ATW_SENSORS: tuple[MelcloudSensorEntityDescription, ...] = (
key="outside_temperature", key="outside_temperature",
name="Outside Temperature", name="Outside Temperature",
icon="mdi:thermometer", icon="mdi:thermometer",
unit_of_measurement=TEMP_CELSIUS, native_unit_of_measurement=TEMP_CELSIUS,
device_class=DEVICE_CLASS_TEMPERATURE, device_class=DEVICE_CLASS_TEMPERATURE,
value_fn=lambda x: x.device.outside_temperature, value_fn=lambda x: x.device.outside_temperature,
enabled=lambda x: True, enabled=lambda x: True,
@ -70,7 +70,7 @@ ATW_SENSORS: tuple[MelcloudSensorEntityDescription, ...] = (
key="tank_temperature", key="tank_temperature",
name="Tank Temperature", name="Tank Temperature",
icon="mdi:thermometer", icon="mdi:thermometer",
unit_of_measurement=TEMP_CELSIUS, native_unit_of_measurement=TEMP_CELSIUS,
device_class=DEVICE_CLASS_TEMPERATURE, device_class=DEVICE_CLASS_TEMPERATURE,
value_fn=lambda x: x.device.tank_temperature, value_fn=lambda x: x.device.tank_temperature,
enabled=lambda x: True, enabled=lambda x: True,
@ -81,7 +81,7 @@ ATW_ZONE_SENSORS: tuple[MelcloudSensorEntityDescription, ...] = (
key="room_temperature", key="room_temperature",
name="Room Temperature", name="Room Temperature",
icon="mdi:thermometer", icon="mdi:thermometer",
unit_of_measurement=TEMP_CELSIUS, native_unit_of_measurement=TEMP_CELSIUS,
device_class=DEVICE_CLASS_TEMPERATURE, device_class=DEVICE_CLASS_TEMPERATURE,
value_fn=lambda zone: zone.room_temperature, value_fn=lambda zone: zone.room_temperature,
enabled=lambda x: True, enabled=lambda x: True,
@ -90,7 +90,7 @@ ATW_ZONE_SENSORS: tuple[MelcloudSensorEntityDescription, ...] = (
key="flow_temperature", key="flow_temperature",
name="Flow Temperature", name="Flow Temperature",
icon="mdi:thermometer", icon="mdi:thermometer",
unit_of_measurement=TEMP_CELSIUS, native_unit_of_measurement=TEMP_CELSIUS,
device_class=DEVICE_CLASS_TEMPERATURE, device_class=DEVICE_CLASS_TEMPERATURE,
value_fn=lambda zone: zone.flow_temperature, value_fn=lambda zone: zone.flow_temperature,
enabled=lambda x: True, enabled=lambda x: True,
@ -99,7 +99,7 @@ ATW_ZONE_SENSORS: tuple[MelcloudSensorEntityDescription, ...] = (
key="return_temperature", key="return_temperature",
name="Flow Return Temperature", name="Flow Return Temperature",
icon="mdi:thermometer", icon="mdi:thermometer",
unit_of_measurement=TEMP_CELSIUS, native_unit_of_measurement=TEMP_CELSIUS,
device_class=DEVICE_CLASS_TEMPERATURE, device_class=DEVICE_CLASS_TEMPERATURE,
value_fn=lambda zone: zone.return_temperature, value_fn=lambda zone: zone.return_temperature,
enabled=lambda x: True, enabled=lambda x: True,
@ -156,7 +156,7 @@ class MelDeviceSensor(SensorEntity):
self._attr_last_reset = dt_util.utc_from_timestamp(0) self._attr_last_reset = dt_util.utc_from_timestamp(0)
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self.entity_description.value_fn(self._api) 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}" self._attr_name = f"{api.name} {zone.name} {description.name}"
@property @property
def state(self): def native_value(self):
"""Return zone based state.""" """Return zone based state."""
return self.entity_description.value_fn(self._zone) return self.entity_description.value_fn(self._zone)

View File

@ -109,7 +109,7 @@ class MeteoFranceSensor(CoordinatorEntity, SensorEntity):
} }
@property @property
def state(self): def native_value(self):
"""Return the state.""" """Return the state."""
path = SENSOR_TYPES[self._type][ENTITY_API_DATA_PATH].split(":") path = SENSOR_TYPES[self._type][ENTITY_API_DATA_PATH].split(":")
data = getattr(self.coordinator.data, path[0]) data = getattr(self.coordinator.data, path[0])
@ -135,7 +135,7 @@ class MeteoFranceSensor(CoordinatorEntity, SensorEntity):
return value return value
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement.""" """Return the unit of measurement."""
return SENSOR_TYPES[self._type][ENTITY_UNIT] return SENSOR_TYPES[self._type][ENTITY_UNIT]
@ -164,7 +164,7 @@ class MeteoFranceRainSensor(MeteoFranceSensor):
"""Representation of a Meteo-France rain sensor.""" """Representation of a Meteo-France rain sensor."""
@property @property
def state(self): def native_value(self):
"""Return the state.""" """Return the state."""
# search first cadran with rain # search first cadran with rain
next_rain = next( next_rain = next(
@ -202,7 +202,7 @@ class MeteoFranceAlertSensor(MeteoFranceSensor):
self._unique_id = self._name self._unique_id = self._name
@property @property
def state(self): def native_value(self):
"""Return the state.""" """Return the state."""
return get_warning_text_status_from_indice_color( return get_warning_text_status_from_indice_color(
self.coordinator.data.get_domain_max_color() self.coordinator.data.get_domain_max_color()

View File

@ -51,7 +51,9 @@ class MeteoclimaticSensor(CoordinatorEntity, SensorEntity):
f"{station.name} {SENSOR_TYPES[sensor_type][SENSOR_TYPE_NAME]}" f"{station.name} {SENSOR_TYPES[sensor_type][SENSOR_TYPE_NAME]}"
) )
self._attr_unique_id = f"{station.code}_{sensor_type}" 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 @property
def device_info(self): def device_info(self):
@ -65,7 +67,7 @@ class MeteoclimaticSensor(CoordinatorEntity, SensorEntity):
} }
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return ( return (
getattr(self.coordinator.data["weather"], self._type) getattr(self.coordinator.data["weather"], self._type)

View File

@ -42,7 +42,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
key="name", key="name",
name="Station Name", name="Station Name",
device_class=None, device_class=None,
unit_of_measurement=None, native_unit_of_measurement=None,
icon="mdi:label-outline", icon="mdi:label-outline",
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
@ -50,7 +50,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
key="weather", key="weather",
name="Weather", name="Weather",
device_class=None, device_class=None,
unit_of_measurement=None, native_unit_of_measurement=None,
icon="mdi:weather-sunny", # but will adapt to current conditions icon="mdi:weather-sunny", # but will adapt to current conditions
entity_registry_enabled_default=True, entity_registry_enabled_default=True,
), ),
@ -58,7 +58,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
key="temperature", key="temperature",
name="Temperature", name="Temperature",
device_class=DEVICE_CLASS_TEMPERATURE, device_class=DEVICE_CLASS_TEMPERATURE,
unit_of_measurement=TEMP_CELSIUS, native_unit_of_measurement=TEMP_CELSIUS,
icon=None, icon=None,
entity_registry_enabled_default=True, entity_registry_enabled_default=True,
), ),
@ -66,7 +66,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
key="feels_like_temperature", key="feels_like_temperature",
name="Feels Like Temperature", name="Feels Like Temperature",
device_class=DEVICE_CLASS_TEMPERATURE, device_class=DEVICE_CLASS_TEMPERATURE,
unit_of_measurement=TEMP_CELSIUS, native_unit_of_measurement=TEMP_CELSIUS,
icon=None, icon=None,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
@ -74,7 +74,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
key="wind_speed", key="wind_speed",
name="Wind Speed", name="Wind Speed",
device_class=None, device_class=None,
unit_of_measurement=SPEED_MILES_PER_HOUR, native_unit_of_measurement=SPEED_MILES_PER_HOUR,
icon="mdi:weather-windy", icon="mdi:weather-windy",
entity_registry_enabled_default=True, entity_registry_enabled_default=True,
), ),
@ -82,7 +82,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
key="wind_direction", key="wind_direction",
name="Wind Direction", name="Wind Direction",
device_class=None, device_class=None,
unit_of_measurement=None, native_unit_of_measurement=None,
icon="mdi:compass-outline", icon="mdi:compass-outline",
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
@ -90,7 +90,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
key="wind_gust", key="wind_gust",
name="Wind Gust", name="Wind Gust",
device_class=None, device_class=None,
unit_of_measurement=SPEED_MILES_PER_HOUR, native_unit_of_measurement=SPEED_MILES_PER_HOUR,
icon="mdi:weather-windy", icon="mdi:weather-windy",
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
@ -98,7 +98,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
key="visibility", key="visibility",
name="Visibility", name="Visibility",
device_class=None, device_class=None,
unit_of_measurement=None, native_unit_of_measurement=None,
icon="mdi:eye", icon="mdi:eye",
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
@ -106,7 +106,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
key="visibility_distance", key="visibility_distance",
name="Visibility Distance", name="Visibility Distance",
device_class=None, device_class=None,
unit_of_measurement=LENGTH_KILOMETERS, native_unit_of_measurement=LENGTH_KILOMETERS,
icon="mdi:eye", icon="mdi:eye",
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
@ -114,7 +114,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
key="uv", key="uv",
name="UV Index", name="UV Index",
device_class=None, device_class=None,
unit_of_measurement=UV_INDEX, native_unit_of_measurement=UV_INDEX,
icon="mdi:weather-sunny-alert", icon="mdi:weather-sunny-alert",
entity_registry_enabled_default=True, entity_registry_enabled_default=True,
), ),
@ -122,7 +122,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
key="precipitation", key="precipitation",
name="Probability of Precipitation", name="Probability of Precipitation",
device_class=None, device_class=None,
unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
icon="mdi:weather-rainy", icon="mdi:weather-rainy",
entity_registry_enabled_default=True, entity_registry_enabled_default=True,
), ),
@ -130,7 +130,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
key="humidity", key="humidity",
name="Humidity", name="Humidity",
device_class=DEVICE_CLASS_HUMIDITY, device_class=DEVICE_CLASS_HUMIDITY,
unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
icon=None, icon=None,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
@ -189,7 +189,7 @@ class MetOfficeCurrentSensor(CoordinatorEntity, SensorEntity):
self.use_3hourly = use_3hourly self.use_3hourly = use_3hourly
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
value = None value = None

View File

@ -88,7 +88,7 @@ class MfiSensor(SensorEntity):
return self._port.label return self._port.label
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
try: try:
tag = self._port.tag tag = self._port.tag
@ -115,7 +115,7 @@ class MfiSensor(SensorEntity):
return None return None
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any.""" """Return the unit of measurement of this entity, if any."""
try: try:
tag = self._port.tag tag = self._port.tag

View File

@ -90,12 +90,12 @@ class MHZ19Sensor(SensorEntity):
return f"{self._name}: {SENSOR_TYPES[self._sensor_type][0]}" return f"{self._name}: {SENSOR_TYPES[self._sensor_type][0]}"
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._ppm if self._sensor_type == SENSOR_CO2 else self._temperature return self._ppm if self._sensor_type == SENSOR_CO2 else self._temperature
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any.""" """Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement return self._unit_of_measurement

View File

@ -180,7 +180,7 @@ class MiFloraSensor(SensorEntity):
return self._name return self._name
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._state return self._state
@ -207,7 +207,7 @@ class MiFloraSensor(SensorEntity):
return STATE_CLASS_MEASUREMENT return STATE_CLASS_MEASUREMENT
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the units of measurement.""" """Return the units of measurement."""
return self._unit return self._unit

View File

@ -172,7 +172,7 @@ class MinMaxSensor(SensorEntity):
return self._name return self._name
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
if self._unit_of_measurement_mismatch: if self._unit_of_measurement_mismatch:
return None return None
@ -181,7 +181,7 @@ class MinMaxSensor(SensorEntity):
) )
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit the value is expressed in.""" """Return the unit the value is expressed in."""
if self._unit_of_measurement_mismatch: if self._unit_of_measurement_mismatch:
return "ERR" return "ERR"

View File

@ -70,12 +70,12 @@ class MinecraftServerSensorEntity(MinecraftServerEntity, SensorEntity):
return self._server.online return self._server.online
@property @property
def state(self) -> Any: def native_value(self) -> Any:
"""Return sensor state.""" """Return sensor state."""
return self._state return self._state
@property @property
def unit_of_measurement(self) -> str: def native_unit_of_measurement(self) -> str:
"""Return sensor measurement unit.""" """Return sensor measurement unit."""
return self._unit return self._unit

View File

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

View File

@ -74,11 +74,11 @@ class MobileAppSensor(MobileAppEntity, SensorEntity):
"""Representation of an mobile app sensor.""" """Representation of an mobile app sensor."""
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._config[ATTR_SENSOR_STATE] return self._config[ATTR_SENSOR_STATE]
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement this sensor expresses itself in.""" """Return the unit of measurement this sensor expresses itself in."""
return self._config.get(ATTR_SENSOR_UOM) return self._config.get(ATTR_SENSOR_UOM)

View File

@ -47,14 +47,14 @@ class ModbusRegisterSensor(BaseStructPlatform, RestoreEntity, SensorEntity):
) -> None: ) -> None:
"""Initialize the modbus register sensor.""" """Initialize the modbus register sensor."""
super().__init__(hub, entry) 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): async def async_added_to_hass(self):
"""Handle entity which will be added.""" """Handle entity which will be added."""
await self.async_base_added_to_hass() await self.async_base_added_to_hass()
state = await self.async_get_last_state() state = await self.async_get_last_state()
if state: if state:
self._attr_state = state.state self._attr_native_value = state.state
async def async_update(self, now=None): async def async_update(self, now=None):
"""Update the state of the sensor.""" """Update the state of the sensor."""
@ -68,6 +68,6 @@ class ModbusRegisterSensor(BaseStructPlatform, RestoreEntity, SensorEntity):
self.async_write_ha_state() self.async_write_ha_state()
return 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._attr_available = True
self.async_write_ha_state() self.async_write_ha_state()

View File

@ -75,7 +75,7 @@ class ModemCalleridSensor(SensorEntity):
return ICON return ICON
@property @property
def state(self): def native_value(self):
"""Return the state of the device.""" """Return the state of the device."""
return self._state return self._state

View File

@ -73,7 +73,7 @@ class ModernFormsLightTimerRemainingTimeSensor(ModernFormsSensor):
self._attr_device_class = DEVICE_CLASS_TIMESTAMP self._attr_device_class = DEVICE_CLASS_TIMESTAMP
@property @property
def state(self) -> StateType: def native_value(self) -> StateType:
"""Return the state of the sensor.""" """Return the state of the sensor."""
sleep_time: datetime = dt_util.utc_from_timestamp( sleep_time: datetime = dt_util.utc_from_timestamp(
self.coordinator.data.state.light_sleep_timer self.coordinator.data.state.light_sleep_timer
@ -103,7 +103,7 @@ class ModernFormsFanTimerRemainingTimeSensor(ModernFormsSensor):
self._attr_device_class = DEVICE_CLASS_TIMESTAMP self._attr_device_class = DEVICE_CLASS_TIMESTAMP
@property @property
def state(self) -> StateType: def native_value(self) -> StateType:
"""Return the state of the sensor.""" """Return the state of the sensor."""
sleep_time: datetime = dt_util.utc_from_timestamp( sleep_time: datetime = dt_util.utc_from_timestamp(
self.coordinator.data.state.fan_sleep_timer self.coordinator.data.state.fan_sleep_timer

View File

@ -359,12 +359,12 @@ class MoldIndicator(SensorEntity):
return self._name return self._name
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement.""" """Return the unit of measurement."""
return PERCENTAGE return PERCENTAGE
@property @property
def state(self): def native_value(self):
"""Return the state of the entity.""" """Return the state of the entity."""
return self._state return self._state

View File

@ -60,7 +60,7 @@ class MoonSensor(SensorEntity):
return "moon__phase" return "moon__phase"
@property @property
def state(self): def native_value(self):
"""Return the state of the device.""" """Return the state of the device."""
if self._state == 0: if self._state == 0:
return STATE_NEW_MOON return STATE_NEW_MOON

View File

@ -47,7 +47,7 @@ class MotionBatterySensor(CoordinatorEntity, SensorEntity):
""" """
_attr_device_class = DEVICE_CLASS_BATTERY _attr_device_class = DEVICE_CLASS_BATTERY
_attr_unit_of_measurement = PERCENTAGE _attr_native_unit_of_measurement = PERCENTAGE
def __init__(self, coordinator, blind): def __init__(self, coordinator, blind):
"""Initialize the Motion Battery Sensor.""" """Initialize the Motion Battery Sensor."""
@ -70,7 +70,7 @@ class MotionBatterySensor(CoordinatorEntity, SensorEntity):
return self.coordinator.data[self._blind.mac][ATTR_AVAILABLE] return self.coordinator.data[self._blind.mac][ATTR_AVAILABLE]
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._blind.battery_level return self._blind.battery_level
@ -106,7 +106,7 @@ class MotionTDBUBatterySensor(MotionBatterySensor):
self._attr_name = f"{blind.blind_type}-{motor}-battery-{blind.mac[12:]}" self._attr_name = f"{blind.blind_type}-{motor}-battery-{blind.mac[12:]}"
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
if self._blind.battery_level is None: if self._blind.battery_level is None:
return None return None
@ -128,7 +128,7 @@ class MotionSignalStrengthSensor(CoordinatorEntity, SensorEntity):
_attr_device_class = DEVICE_CLASS_SIGNAL_STRENGTH _attr_device_class = DEVICE_CLASS_SIGNAL_STRENGTH
_attr_entity_registry_enabled_default = False _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): def __init__(self, coordinator, device, device_type):
"""Initialize the Motion Signal Strength Sensor.""" """Initialize the Motion Signal Strength Sensor."""
@ -162,7 +162,7 @@ class MotionSignalStrengthSensor(CoordinatorEntity, SensorEntity):
) )
@property @property
def state(self): def native_value(self):
"""Return the state of the sensor.""" """Return the state of the sensor."""
return self._device.RSSI return self._device.RSSI

View File

@ -214,7 +214,7 @@ class MqttSensor(MqttEntity, SensorEntity):
self.async_write_ha_state() self.async_write_ha_state()
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit this state is expressed in.""" """Return the unit this state is expressed in."""
return self._config.get(CONF_UNIT_OF_MEASUREMENT) return self._config.get(CONF_UNIT_OF_MEASUREMENT)
@ -224,7 +224,7 @@ class MqttSensor(MqttEntity, SensorEntity):
return self._config[CONF_FORCE_UPDATE] return self._config[CONF_FORCE_UPDATE]
@property @property
def state(self): def native_value(self):
"""Return the state of the entity.""" """Return the state of the entity."""
return self._state return self._state

View File

@ -139,7 +139,7 @@ class MQTTRoomSensor(SensorEntity):
return {ATTR_DISTANCE: self._distance} return {ATTR_DISTANCE: self._distance}
@property @property
def state(self): def native_value(self):
"""Return the current room of the entity.""" """Return the current room of the entity."""
return self._state return self._state

View File

@ -108,7 +108,7 @@ class MVGLiveSensor(SensorEntity):
return self._station return self._station
@property @property
def state(self): def native_value(self):
"""Return the next departure time.""" """Return the next departure time."""
return self._state return self._state
@ -128,7 +128,7 @@ class MVGLiveSensor(SensorEntity):
return self._icon return self._icon
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit this state is expressed in.""" """Return the unit this state is expressed in."""
return TIME_MINUTES return TIME_MINUTES

View File

@ -98,7 +98,7 @@ class MyChevyStatus(SensorEntity):
return self._name return self._name
@property @property
def state(self): def native_value(self):
"""Return the state.""" """Return the state."""
return self._state return self._state
@ -166,7 +166,7 @@ class EVSensor(SensorEntity):
self.async_write_ha_state() self.async_write_ha_state()
@property @property
def state(self): def native_value(self):
"""Return the state.""" """Return the state."""
return self._state return self._state
@ -176,7 +176,7 @@ class EVSensor(SensorEntity):
return self._state_attributes return self._state_attributes
@property @property
def unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit of measurement the state is expressed in.""" """Return the unit of measurement the state is expressed in."""
return self._unit_of_measurement return self._unit_of_measurement

View File

@ -147,8 +147,8 @@ class MySensorsSensor(mysensors.device.MySensorsEntity, SensorEntity):
return True return True
@property @property
def state(self) -> str | None: def native_value(self) -> str | None:
"""Return the state of this entity.""" """Return the state of the device."""
return self._values.get(self.value_type) return self._values.get(self.value_type)
@property @property
@ -176,7 +176,7 @@ class MySensorsSensor(mysensors.device.MySensorsEntity, SensorEntity):
return self._get_sensor_type()[3] return self._get_sensor_type()[3]
@property @property
def unit_of_measurement(self) -> str | None: def native_unit_of_measurement(self) -> str | None:
"""Return the unit of measurement of this entity.""" """Return the unit of measurement of this entity."""
set_req = self.gateway.const.SetReq set_req = self.gateway.const.SetReq
if ( if (

View File

@ -26,6 +26,7 @@ async def test_sleep_time_sensor_with_none_state(hass):
sensor = LitterRobotSleepTimeSensor( sensor = LitterRobotSleepTimeSensor(
robot, "Sleep Mode Start Time", Mock(), "sleep_mode_start_time" robot, "Sleep Mode Start Time", Mock(), "sleep_mode_start_time"
) )
sensor.hass = hass
assert sensor assert sensor
assert sensor.state is None assert sensor.state is None

View File

@ -121,7 +121,9 @@ def port_fixture():
@pytest.fixture(name="sensor") @pytest.fixture(name="sensor")
def sensor_fixture(hass, port): def sensor_fixture(hass, port):
"""Sensor fixture.""" """Sensor fixture."""
return mfi.MfiSensor(port, hass) sensor = mfi.MfiSensor(port, hass)
sensor.hass = hass
return sensor
async def test_name(port, sensor): async def test_name(port, sensor):

View File

@ -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)) @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.""" """Test CO2 sensor."""
client = mhz19.MHZClient(co2sensor, "test.serial") client = mhz19.MHZClient(co2sensor, "test.serial")
sensor = mhz19.MHZ19Sensor(client, mhz19.SENSOR_CO2, None, "name") sensor = mhz19.MHZ19Sensor(client, mhz19.SENSOR_CO2, None, "name")
sensor.hass = hass
sensor.update() sensor.update()
assert sensor.name == "name: CO2" 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)) @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.""" """Test temperature sensor."""
client = mhz19.MHZClient(co2sensor, "test.serial") client = mhz19.MHZClient(co2sensor, "test.serial")
sensor = mhz19.MHZ19Sensor(client, mhz19.SENSOR_TEMPERATURE, None, "name") sensor = mhz19.MHZ19Sensor(client, mhz19.SENSOR_TEMPERATURE, None, "name")
sensor.hass = hass
sensor.update() sensor.update()
assert sensor.name == "name: Temperature" 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)) @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.""" """Test temperature sensor."""
client = mhz19.MHZClient(co2sensor, "test.serial") client = mhz19.MHZClient(co2sensor, "test.serial")
sensor = mhz19.MHZ19Sensor( sensor = mhz19.MHZ19Sensor(
client, mhz19.SENSOR_TEMPERATURE, TEMP_FAHRENHEIT, "name" client, mhz19.SENSOR_TEMPERATURE, TEMP_FAHRENHEIT, "name"
) )
sensor.hass = hass
sensor.update() sensor.update()
assert sensor.state == 75.2 assert sensor.state == 75.2