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:
parent
ae507aeed1
commit
2720ba2753
70 changed files with 195 additions and 183 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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]
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 (
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue