mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Move temperature conversions to sensor base class (6/8) (#54476)
* Move temperature conversions to entity base class (6/8) * Fix tests
This commit is contained in:
parent
6de6a5dc14
commit
e558b3463e
@ -127,7 +127,7 @@ class RadarrSensor(SensorEntity):
|
||||
return "{} {}".format("Radarr", self._name)
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return sensor state."""
|
||||
return self._state
|
||||
|
||||
@ -137,7 +137,7 @@ class RadarrSensor(SensorEntity):
|
||||
return self._available
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of the sensor."""
|
||||
return self._unit
|
||||
|
||||
|
@ -45,6 +45,6 @@ class RainBirdSensor(SensorEntity):
|
||||
"""Get the latest data and updates the states."""
|
||||
_LOGGER.debug("Updating sensor: %s", self.name)
|
||||
if self.entity_description.key == SENSOR_TYPE_RAINSENSOR:
|
||||
self._attr_state = self._controller.get_rain_sensor_state()
|
||||
self._attr_native_value = self._controller.get_rain_sensor_state()
|
||||
elif self.entity_description.key == SENSOR_TYPE_RAINDELAY:
|
||||
self._attr_state = self._controller.get_rain_delay()
|
||||
self._attr_native_value = self._controller.get_rain_delay()
|
||||
|
@ -48,12 +48,12 @@ class RainCloudSensor(RainCloudEntity, SensorEntity):
|
||||
"""A sensor implementation for raincloud device."""
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the units of measurement."""
|
||||
return UNIT_OF_MEASUREMENT_MAP.get(self._sensor_type)
|
||||
|
||||
|
@ -131,7 +131,7 @@ class EagleSensor(SensorEntity):
|
||||
self._type = sensor_type
|
||||
sensor_info = SENSORS[sensor_type]
|
||||
self._attr_name = sensor_info.name
|
||||
self._attr_unit_of_measurement = sensor_info.unit_of_measurement
|
||||
self._attr_native_unit_of_measurement = sensor_info.unit_of_measurement
|
||||
self._attr_device_class = sensor_info.device_class
|
||||
self._attr_state_class = sensor_info.state_class
|
||||
self._attr_last_reset = sensor_info.last_reset
|
||||
@ -139,7 +139,7 @@ class EagleSensor(SensorEntity):
|
||||
def update(self):
|
||||
"""Get the energy information from the Rainforest Eagle."""
|
||||
self.eagle_data.update()
|
||||
self._attr_state = self.eagle_data.get_state(self._type)
|
||||
self._attr_native_value = self.eagle_data.get_state(self._type)
|
||||
|
||||
|
||||
class EagleData:
|
||||
|
@ -134,7 +134,7 @@ class RainMachineSensor(RainMachineEntity, SensorEntity):
|
||||
self._attr_entity_registry_enabled_default = enabled_by_default
|
||||
self._attr_icon = icon
|
||||
self._attr_name = name
|
||||
self._attr_unit_of_measurement = unit
|
||||
self._attr_native_unit_of_measurement = unit
|
||||
|
||||
|
||||
class ProvisionSettingsSensor(RainMachineSensor):
|
||||
@ -144,7 +144,7 @@ class ProvisionSettingsSensor(RainMachineSensor):
|
||||
def update_from_latest_data(self) -> None:
|
||||
"""Update the state."""
|
||||
if self._entity_type == TYPE_FLOW_SENSOR_CLICK_M3:
|
||||
self._attr_state = self.coordinator.data["system"].get(
|
||||
self._attr_native_value = self.coordinator.data["system"].get(
|
||||
"flowSensorClicksPerCubicMeter"
|
||||
)
|
||||
elif self._entity_type == TYPE_FLOW_SENSOR_CONSUMED_LITERS:
|
||||
@ -154,15 +154,15 @@ class ProvisionSettingsSensor(RainMachineSensor):
|
||||
)
|
||||
|
||||
if clicks and clicks_per_m3:
|
||||
self._attr_state = (clicks * 1000) / clicks_per_m3
|
||||
self._attr_native_value = (clicks * 1000) / clicks_per_m3
|
||||
else:
|
||||
self._attr_state = None
|
||||
self._attr_native_value = None
|
||||
elif self._entity_type == TYPE_FLOW_SENSOR_START_INDEX:
|
||||
self._attr_state = self.coordinator.data["system"].get(
|
||||
self._attr_native_value = self.coordinator.data["system"].get(
|
||||
"flowSensorStartIndex"
|
||||
)
|
||||
elif self._entity_type == TYPE_FLOW_SENSOR_WATERING_CLICKS:
|
||||
self._attr_state = self.coordinator.data["system"].get(
|
||||
self._attr_native_value = self.coordinator.data["system"].get(
|
||||
"flowSensorWateringClicks"
|
||||
)
|
||||
|
||||
@ -174,4 +174,4 @@ class UniversalRestrictionsSensor(RainMachineSensor):
|
||||
def update_from_latest_data(self) -> None:
|
||||
"""Update the state."""
|
||||
if self._entity_type == TYPE_FREEZE_TEMP:
|
||||
self._attr_state = self.coordinator.data["freezeProtectTemp"]
|
||||
self._attr_native_value = self.coordinator.data["freezeProtectTemp"]
|
||||
|
@ -58,7 +58,7 @@ class RandomSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the device."""
|
||||
return self._state
|
||||
|
||||
@ -68,7 +68,7 @@ class RandomSensor(SensorEntity):
|
||||
return ICON
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit this state is expressed in."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
|
@ -127,4 +127,4 @@ class ReCollectWasteSensor(CoordinatorEntity, SensorEntity):
|
||||
ATTR_NEXT_PICKUP_DATE: as_utc(next_pickup_event.date).isoformat(),
|
||||
}
|
||||
)
|
||||
self._attr_state = as_utc(pickup_event.date).isoformat()
|
||||
self._attr_native_value = as_utc(pickup_event.date).isoformat()
|
||||
|
@ -99,7 +99,7 @@ class RedditSensor(SensorEntity):
|
||||
return f"reddit_{self._subreddit}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return len(self._subreddit_data)
|
||||
|
||||
|
@ -105,7 +105,7 @@ class RejseplanenTransportSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@ -131,7 +131,7 @@ class RejseplanenTransportSensor(SensorEntity):
|
||||
return attributes
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit this state is expressed in."""
|
||||
return TIME_MINUTES
|
||||
|
||||
|
@ -77,7 +77,7 @@ class RepetierSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement of this entity, if any."""
|
||||
return SENSOR_TYPES[self._sensor_type][1]
|
||||
|
||||
@ -92,7 +92,7 @@ class RepetierSensor(SensorEntity):
|
||||
return False
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return sensor state."""
|
||||
return self._state
|
||||
|
||||
@ -134,7 +134,7 @@ class RepetierTempSensor(RepetierSensor):
|
||||
"""Represent a Repetier temp sensor."""
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return sensor state."""
|
||||
if self._state is None:
|
||||
return None
|
||||
@ -156,7 +156,7 @@ class RepetierJobSensor(RepetierSensor):
|
||||
"""Represent a Repetier job sensor."""
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return sensor state."""
|
||||
if self._state is None:
|
||||
return None
|
||||
|
@ -115,12 +115,12 @@ class RestSensor(RestEntity, SensorEntity):
|
||||
self._json_attrs_path = json_attrs_path
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit the value is expressed in."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the device."""
|
||||
return self._state
|
||||
|
||||
|
@ -152,12 +152,12 @@ class RflinkSensor(RflinkDevice, SensorEntity):
|
||||
self.handle_event_callback(self._initial_event)
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return measurement unit."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return value."""
|
||||
return self._state
|
||||
|
||||
|
@ -78,92 +78,92 @@ SENSOR_TYPES = (
|
||||
key="Barameter",
|
||||
device_class=DEVICE_CLASS_PRESSURE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
unit_of_measurement=PRESSURE_HPA,
|
||||
native_unit_of_measurement=PRESSURE_HPA,
|
||||
),
|
||||
RfxtrxSensorEntityDescription(
|
||||
key="Battery numeric",
|
||||
device_class=DEVICE_CLASS_BATTERY,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
unit_of_measurement=PERCENTAGE,
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
convert=_battery_convert,
|
||||
),
|
||||
RfxtrxSensorEntityDescription(
|
||||
key="Current",
|
||||
device_class=DEVICE_CLASS_CURRENT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
),
|
||||
RfxtrxSensorEntityDescription(
|
||||
key="Current Ch. 1",
|
||||
device_class=DEVICE_CLASS_CURRENT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
),
|
||||
RfxtrxSensorEntityDescription(
|
||||
key="Current Ch. 2",
|
||||
device_class=DEVICE_CLASS_CURRENT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
),
|
||||
RfxtrxSensorEntityDescription(
|
||||
key="Current Ch. 3",
|
||||
device_class=DEVICE_CLASS_CURRENT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
),
|
||||
RfxtrxSensorEntityDescription(
|
||||
key="Energy usage",
|
||||
device_class=DEVICE_CLASS_POWER,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
unit_of_measurement=POWER_WATT,
|
||||
native_unit_of_measurement=POWER_WATT,
|
||||
),
|
||||
RfxtrxSensorEntityDescription(
|
||||
key="Humidity",
|
||||
device_class=DEVICE_CLASS_HUMIDITY,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
unit_of_measurement=PERCENTAGE,
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
),
|
||||
RfxtrxSensorEntityDescription(
|
||||
key="Rssi numeric",
|
||||
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||
convert=_rssi_convert,
|
||||
),
|
||||
RfxtrxSensorEntityDescription(
|
||||
key="Temperature",
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
),
|
||||
RfxtrxSensorEntityDescription(
|
||||
key="Temperature2",
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
),
|
||||
RfxtrxSensorEntityDescription(
|
||||
key="Total usage",
|
||||
device_class=DEVICE_CLASS_ENERGY,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
last_reset=dt.utc_from_timestamp(0),
|
||||
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
),
|
||||
RfxtrxSensorEntityDescription(
|
||||
key="Voltage",
|
||||
device_class=DEVICE_CLASS_VOLTAGE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
),
|
||||
RfxtrxSensorEntityDescription(
|
||||
key="Wind direction",
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
unit_of_measurement=DEGREE,
|
||||
native_unit_of_measurement=DEGREE,
|
||||
),
|
||||
RfxtrxSensorEntityDescription(
|
||||
key="Rain rate",
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
unit_of_measurement=PRECIPITATION_MILLIMETERS_PER_HOUR,
|
||||
native_unit_of_measurement=PRECIPITATION_MILLIMETERS_PER_HOUR,
|
||||
),
|
||||
RfxtrxSensorEntityDescription(
|
||||
key="Sound",
|
||||
@ -175,34 +175,34 @@ SENSOR_TYPES = (
|
||||
key="Count",
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
last_reset=dt.utc_from_timestamp(0),
|
||||
unit_of_measurement="count",
|
||||
native_unit_of_measurement="count",
|
||||
),
|
||||
RfxtrxSensorEntityDescription(
|
||||
key="Counter value",
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
last_reset=dt.utc_from_timestamp(0),
|
||||
unit_of_measurement="count",
|
||||
native_unit_of_measurement="count",
|
||||
),
|
||||
RfxtrxSensorEntityDescription(
|
||||
key="Chill",
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
unit_of_measurement=TEMP_CELSIUS,
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
),
|
||||
RfxtrxSensorEntityDescription(
|
||||
key="Wind average speed",
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
unit_of_measurement=SPEED_METERS_PER_SECOND,
|
||||
native_unit_of_measurement=SPEED_METERS_PER_SECOND,
|
||||
),
|
||||
RfxtrxSensorEntityDescription(
|
||||
key="Wind gust",
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
unit_of_measurement=SPEED_METERS_PER_SECOND,
|
||||
native_unit_of_measurement=SPEED_METERS_PER_SECOND,
|
||||
),
|
||||
RfxtrxSensorEntityDescription(
|
||||
key="Rain total",
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
unit_of_measurement=LENGTH_MILLIMETERS,
|
||||
native_unit_of_measurement=LENGTH_MILLIMETERS,
|
||||
),
|
||||
RfxtrxSensorEntityDescription(
|
||||
key="Forecast",
|
||||
@ -216,7 +216,7 @@ SENSOR_TYPES = (
|
||||
RfxtrxSensorEntityDescription(
|
||||
key="UV",
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
unit_of_measurement=UV_INDEX,
|
||||
native_unit_of_measurement=UV_INDEX,
|
||||
),
|
||||
)
|
||||
|
||||
@ -313,7 +313,7 @@ class RfxtrxSensor(RfxtrxEntity, SensorEntity):
|
||||
self._apply_event(get_rfx_object(event))
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
if not self._event:
|
||||
return None
|
||||
|
@ -56,7 +56,7 @@ class RingSensor(RingEntityMixin, SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
if self._sensor_type == "volume":
|
||||
return self._device.volume
|
||||
@ -84,7 +84,7 @@ class RingSensor(RingEntityMixin, SensorEntity):
|
||||
return self._icon
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the units of measurement."""
|
||||
return SENSOR_TYPES.get(self._sensor_type)[2]
|
||||
|
||||
@ -120,7 +120,7 @@ class HealthDataRingSensor(RingSensor):
|
||||
return False
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
if self._sensor_type == "wifi_signal_category":
|
||||
return self._device.wifi_signal_category
|
||||
@ -172,7 +172,7 @@ class HistoryRingSensor(RingSensor):
|
||||
self.async_write_ha_state()
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
if self._latest_event is None:
|
||||
return None
|
||||
|
@ -46,12 +46,12 @@ class RippleSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement this sensor expresses itself in."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
|
@ -87,7 +87,7 @@ class RiscoSensor(CoordinatorEntity, SensorEntity):
|
||||
self.async_write_ha_state()
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Value of sensor."""
|
||||
if self._event is None:
|
||||
return None
|
||||
|
@ -59,7 +59,7 @@ class DiffuserPerfumeSensor(DiffuserEntity):
|
||||
return "mdi:tag-remove"
|
||||
|
||||
@property
|
||||
def state(self) -> str:
|
||||
def native_value(self) -> str:
|
||||
"""Return the state of the perfume sensor."""
|
||||
return self._diffuser.perfume
|
||||
|
||||
@ -81,7 +81,7 @@ class DiffuserFillSensor(DiffuserEntity):
|
||||
return "mdi:beaker-question"
|
||||
|
||||
@property
|
||||
def state(self) -> str:
|
||||
def native_value(self) -> str:
|
||||
"""Return the state of the fill sensor."""
|
||||
return self._diffuser.fill
|
||||
|
||||
@ -90,7 +90,7 @@ class DiffuserBatterySensor(DiffuserEntity):
|
||||
"""Representation of a diffuser battery sensor."""
|
||||
|
||||
_attr_device_class = DEVICE_CLASS_BATTERY
|
||||
_attr_unit_of_measurement = PERCENTAGE
|
||||
_attr_native_unit_of_measurement = PERCENTAGE
|
||||
|
||||
def __init__(
|
||||
self, diffuser: Diffuser, coordinator: RitualsDataUpdateCoordinator
|
||||
@ -99,7 +99,7 @@ class DiffuserBatterySensor(DiffuserEntity):
|
||||
super().__init__(diffuser, coordinator, BATTERY_SUFFIX)
|
||||
|
||||
@property
|
||||
def state(self) -> int:
|
||||
def native_value(self) -> int:
|
||||
"""Return the state of the battery sensor."""
|
||||
return self._diffuser.battery_percentage
|
||||
|
||||
@ -108,7 +108,7 @@ class DiffuserWifiSensor(DiffuserEntity):
|
||||
"""Representation of a diffuser wifi sensor."""
|
||||
|
||||
_attr_device_class = DEVICE_CLASS_SIGNAL_STRENGTH
|
||||
_attr_unit_of_measurement = PERCENTAGE
|
||||
_attr_native_unit_of_measurement = PERCENTAGE
|
||||
|
||||
def __init__(
|
||||
self, diffuser: Diffuser, coordinator: RitualsDataUpdateCoordinator
|
||||
@ -117,6 +117,6 @@ class DiffuserWifiSensor(DiffuserEntity):
|
||||
super().__init__(diffuser, coordinator, WIFI_SUFFIX)
|
||||
|
||||
@property
|
||||
def state(self) -> int:
|
||||
def native_value(self) -> int:
|
||||
"""Return the state of the wifi sensor."""
|
||||
return self._diffuser.wifi_percentage
|
||||
|
@ -145,7 +145,7 @@ class RMVDepartureSensor(SensorEntity):
|
||||
return self._state is not None
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the next departure time."""
|
||||
return self._state
|
||||
|
||||
@ -171,7 +171,7 @@ class RMVDepartureSensor(SensorEntity):
|
||||
return self._icon
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit this state is expressed in."""
|
||||
return TIME_MINUTES
|
||||
|
||||
|
@ -36,7 +36,7 @@ class RoombaBattery(IRobotEntity, SensorEntity):
|
||||
return DEVICE_CLASS_BATTERY
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit_of_measurement of the device."""
|
||||
return PERCENTAGE
|
||||
|
||||
@ -50,6 +50,6 @@ class RoombaBattery(IRobotEntity, SensorEntity):
|
||||
)
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._battery_level
|
||||
|
@ -116,7 +116,7 @@ class RovaSensor(SensorEntity):
|
||||
self.data_service.update()
|
||||
pickup_date = self.data_service.data.get(self.entity_description.key)
|
||||
if pickup_date is not None:
|
||||
self._attr_state = pickup_date.isoformat()
|
||||
self._attr_native_value = pickup_date.isoformat()
|
||||
|
||||
|
||||
class RovaData:
|
||||
|
@ -94,7 +94,7 @@ class RTorrentSensor(SensorEntity):
|
||||
return f"{self.client_name} {self._name}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@ -104,7 +104,7 @@ class RTorrentSensor(SensorEntity):
|
||||
return self._available
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement of this entity, if any."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
|
@ -45,7 +45,7 @@ class SabnzbdSensor(SensorEntity):
|
||||
return f"{self._client_name} {self._name}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@ -55,7 +55,7 @@ class SabnzbdSensor(SensorEntity):
|
||||
return False
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement of this entity, if any."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
|
@ -191,12 +191,12 @@ class SAJsensor(SensorEntity):
|
||||
return f"saj_{self._sensor.name}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit the value is expressed in."""
|
||||
return SAJ_UNIT_MAPPINGS[self._sensor.unit]
|
||||
|
||||
|
@ -108,12 +108,12 @@ class ScrapeSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit the value is expressed in."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the device."""
|
||||
return self._state
|
||||
|
||||
|
@ -114,7 +114,7 @@ class ScreenLogicSensor(ScreenlogicEntity, SensorEntity):
|
||||
return f"{self.gateway_name} {self.sensor['name']}"
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return self.sensor.get("unit")
|
||||
|
||||
@ -125,7 +125,7 @@ class ScreenLogicSensor(ScreenlogicEntity, SensorEntity):
|
||||
return SL_DEVICE_TYPE_TO_HA_DEVICE_CLASS.get(device_type)
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""State of the sensor."""
|
||||
value = self.sensor["value"]
|
||||
return (value - 1) if "supply" in self._data_key else value
|
||||
@ -160,7 +160,7 @@ class ScreenLogicChemistrySensor(ScreenLogicSensor):
|
||||
self._key = key
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""State of the sensor."""
|
||||
value = self.sensor["value"]
|
||||
if "dosing_state" in self._key:
|
||||
|
@ -126,7 +126,7 @@ class Season(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the current season."""
|
||||
return self.season
|
||||
|
||||
|
@ -125,7 +125,7 @@ class SenseActiveSensor(SensorEntity):
|
||||
"""Implementation of a Sense energy sensor."""
|
||||
|
||||
_attr_icon = ICON
|
||||
_attr_unit_of_measurement = POWER_WATT
|
||||
_attr_native_unit_of_measurement = POWER_WATT
|
||||
_attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION}
|
||||
_attr_should_poll = False
|
||||
_attr_available = False
|
||||
@ -168,9 +168,9 @@ class SenseActiveSensor(SensorEntity):
|
||||
if self._is_production
|
||||
else self._data.active_power
|
||||
)
|
||||
if self._attr_available and self._attr_state == new_state:
|
||||
if self._attr_available and self._attr_native_value == new_state:
|
||||
return
|
||||
self._attr_state = new_state
|
||||
self._attr_native_value = new_state
|
||||
self._attr_available = True
|
||||
self.async_write_ha_state()
|
||||
|
||||
@ -178,7 +178,7 @@ class SenseActiveSensor(SensorEntity):
|
||||
class SenseVoltageSensor(SensorEntity):
|
||||
"""Implementation of a Sense energy voltage sensor."""
|
||||
|
||||
_attr_unit_of_measurement = ELECTRIC_POTENTIAL_VOLT
|
||||
_attr_native_unit_of_measurement = ELECTRIC_POTENTIAL_VOLT
|
||||
_attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION}
|
||||
_attr_icon = ICON
|
||||
_attr_should_poll = False
|
||||
@ -212,10 +212,10 @@ class SenseVoltageSensor(SensorEntity):
|
||||
def _async_update_from_data(self):
|
||||
"""Update the sensor from the data. Must not do I/O."""
|
||||
new_state = round(self._data.active_voltage[self._voltage_index], 1)
|
||||
if self._attr_available and self._attr_state == new_state:
|
||||
if self._attr_available and self._attr_native_value == new_state:
|
||||
return
|
||||
self._attr_available = True
|
||||
self._attr_state = new_state
|
||||
self._attr_native_value = new_state
|
||||
self.async_write_ha_state()
|
||||
|
||||
|
||||
@ -224,7 +224,7 @@ class SenseTrendsSensor(SensorEntity):
|
||||
|
||||
_attr_device_class = DEVICE_CLASS_ENERGY
|
||||
_attr_state_class = STATE_CLASS_MEASUREMENT
|
||||
_attr_unit_of_measurement = ENERGY_KILO_WATT_HOUR
|
||||
_attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR
|
||||
_attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION}
|
||||
_attr_icon = ICON
|
||||
_attr_should_poll = False
|
||||
@ -249,7 +249,7 @@ class SenseTrendsSensor(SensorEntity):
|
||||
self._had_any_update = False
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return round(self._data.get_trend(self._sensor_type, self._is_production), 1)
|
||||
|
||||
@ -288,7 +288,7 @@ class SenseEnergyDevice(SensorEntity):
|
||||
|
||||
_attr_available = False
|
||||
_attr_state_class = STATE_CLASS_MEASUREMENT
|
||||
_attr_unit_of_measurement = POWER_WATT
|
||||
_attr_native_unit_of_measurement = POWER_WATT
|
||||
_attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION}
|
||||
_attr_device_class = DEVICE_CLASS_POWER
|
||||
_attr_should_poll = False
|
||||
@ -320,8 +320,8 @@ class SenseEnergyDevice(SensorEntity):
|
||||
new_state = 0
|
||||
else:
|
||||
new_state = int(device_data["w"])
|
||||
if self._attr_available and self._attr_state == new_state:
|
||||
if self._attr_available and self._attr_native_value == new_state:
|
||||
return
|
||||
self._attr_state = new_state
|
||||
self._attr_native_value = new_state
|
||||
self._attr_available = True
|
||||
self.async_write_ha_state()
|
||||
|
@ -86,12 +86,12 @@ class SenseHatSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit the value is expressed in."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
|
@ -245,6 +245,6 @@ class SerialSensor(SensorEntity):
|
||||
return self._attributes
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
@ -71,12 +71,12 @@ class ParticulateMatterSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement of this entity, if any."""
|
||||
return CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
|
||||
|
@ -125,7 +125,7 @@ class SeventeenTrackSummarySensor(SensorEntity):
|
||||
return f"Seventeentrack Packages {self._status}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state."""
|
||||
return self._state
|
||||
|
||||
@ -135,7 +135,7 @@ class SeventeenTrackSummarySensor(SensorEntity):
|
||||
return f"summary_{self._data.account_id}_{slugify(self._status)}"
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit the value is expressed in."""
|
||||
return "packages"
|
||||
|
||||
@ -211,7 +211,7 @@ class SeventeenTrackPackageSensor(SensorEntity):
|
||||
return f"Seventeentrack Package: {name}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state."""
|
||||
return self._state
|
||||
|
||||
|
@ -280,7 +280,7 @@ class ShellySensor(ShellyBlockAttributeEntity, SensorEntity):
|
||||
).replace(second=0, microsecond=0)
|
||||
|
||||
@property
|
||||
def state(self) -> StateType:
|
||||
def native_value(self) -> StateType:
|
||||
"""Return value of sensor."""
|
||||
if (
|
||||
self.description.last_reset == LAST_RESET_UPTIME
|
||||
@ -302,7 +302,7 @@ class ShellySensor(ShellyBlockAttributeEntity, SensorEntity):
|
||||
return self.description.state_class
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self) -> str | None:
|
||||
def native_unit_of_measurement(self) -> str | None:
|
||||
"""Return unit of sensor."""
|
||||
return cast(str, self._unit)
|
||||
|
||||
@ -311,7 +311,7 @@ class ShellyRestSensor(ShellyRestAttributeEntity, SensorEntity):
|
||||
"""Represent a shelly REST sensor."""
|
||||
|
||||
@property
|
||||
def state(self) -> StateType:
|
||||
def native_value(self) -> StateType:
|
||||
"""Return value of sensor."""
|
||||
return self.attribute_value
|
||||
|
||||
@ -321,7 +321,7 @@ class ShellyRestSensor(ShellyRestAttributeEntity, SensorEntity):
|
||||
return self.description.state_class
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self) -> str | None:
|
||||
def native_unit_of_measurement(self) -> str | None:
|
||||
"""Return unit of sensor."""
|
||||
return self.description.unit
|
||||
|
||||
@ -330,7 +330,7 @@ class ShellySleepingSensor(ShellySleepingBlockAttributeEntity, SensorEntity):
|
||||
"""Represent a shelly sleeping sensor."""
|
||||
|
||||
@property
|
||||
def state(self) -> StateType:
|
||||
def native_value(self) -> StateType:
|
||||
"""Return value of sensor."""
|
||||
if self.block is not None:
|
||||
return self.attribute_value
|
||||
@ -343,6 +343,6 @@ class ShellySleepingSensor(ShellySleepingBlockAttributeEntity, SensorEntity):
|
||||
return self.description.state_class
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self) -> str | None:
|
||||
def native_unit_of_measurement(self) -> str | None:
|
||||
"""Return unit of sensor."""
|
||||
return cast(str, self._unit)
|
||||
|
@ -62,12 +62,12 @@ class ShodanSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit the value is expressed in."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
|
@ -108,7 +108,7 @@ class SHTSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@ -123,7 +123,7 @@ class SHTSensorTemperature(SHTSensor):
|
||||
_attr_device_class = DEVICE_CLASS_TEMPERATURE
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return self.hass.config.units.temperature_unit
|
||||
|
||||
@ -141,7 +141,7 @@ class SHTSensorHumidity(SHTSensor):
|
||||
"""Representation of a humidity sensor."""
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return PERCENTAGE
|
||||
|
||||
|
@ -149,7 +149,7 @@ class SigfoxDevice(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the payload of the last message."""
|
||||
return self._state
|
||||
|
||||
|
@ -34,9 +34,9 @@ class SimplisafeFreezeSensor(SimpliSafeBaseSensor, SensorEntity):
|
||||
"""Define a SimpliSafe freeze sensor entity."""
|
||||
|
||||
_attr_device_class = DEVICE_CLASS_TEMPERATURE
|
||||
_attr_unit_of_measurement = TEMP_FAHRENHEIT
|
||||
_attr_native_unit_of_measurement = TEMP_FAHRENHEIT
|
||||
|
||||
@callback
|
||||
def async_update_from_rest_api(self) -> None:
|
||||
"""Update the entity with the provided REST API data."""
|
||||
self._attr_state = self._sensor.temperature
|
||||
self._attr_native_value = self._sensor.temperature
|
||||
|
@ -121,7 +121,7 @@ class SimulatedSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@ -131,7 +131,7 @@ class SimulatedSensor(SensorEntity):
|
||||
return ICON
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit this state is expressed in."""
|
||||
return self._unit
|
||||
|
||||
|
@ -65,7 +65,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
class SkybeaconHumid(SensorEntity):
|
||||
"""Representation of a Skybeacon humidity sensor."""
|
||||
|
||||
_attr_unit_of_measurement = PERCENTAGE
|
||||
_attr_native_unit_of_measurement = PERCENTAGE
|
||||
|
||||
def __init__(self, name, mon):
|
||||
"""Initialize a sensor."""
|
||||
@ -78,7 +78,7 @@ class SkybeaconHumid(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the device."""
|
||||
return self.mon.data["humid"]
|
||||
|
||||
@ -92,7 +92,7 @@ class SkybeaconTemp(SensorEntity):
|
||||
"""Representation of a Skybeacon temperature sensor."""
|
||||
|
||||
_attr_device_class = DEVICE_CLASS_TEMPERATURE
|
||||
_attr_unit_of_measurement = TEMP_CELSIUS
|
||||
_attr_native_unit_of_measurement = TEMP_CELSIUS
|
||||
|
||||
def __init__(self, name, mon):
|
||||
"""Initialize a sensor."""
|
||||
@ -105,7 +105,7 @@ class SkybeaconTemp(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the device."""
|
||||
return self.mon.data["temp"]
|
||||
|
||||
|
@ -71,4 +71,4 @@ class SkybellSensor(SkybellDevice, SensorEntity):
|
||||
super().update()
|
||||
|
||||
if self.entity_description.key == "chime_level":
|
||||
self._attr_state = self._device.outdoor_chime_level
|
||||
self._attr_native_value = self._device.outdoor_chime_level
|
||||
|
@ -37,7 +37,7 @@ class SleepNumberSensor(SleepIQSensor, SensorEntity):
|
||||
self.update()
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
|
@ -179,12 +179,12 @@ class SMAsensor(CoordinatorEntity, SensorEntity):
|
||||
return self._sensor.name
|
||||
|
||||
@property
|
||||
def state(self) -> StateType:
|
||||
def native_value(self) -> StateType:
|
||||
"""Return the state of the sensor."""
|
||||
return self._sensor.value
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self) -> str | None:
|
||||
def native_unit_of_measurement(self) -> str | None:
|
||||
"""Return the unit the value is expressed in."""
|
||||
return self._sensor.unit
|
||||
|
||||
|
@ -282,7 +282,7 @@ class SmappeeSensor(SensorEntity):
|
||||
return self._icon
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@ -292,7 +292,7 @@ class SmappeeSensor(SensorEntity):
|
||||
return self._device_class
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement of this entity, if any."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
|
@ -33,7 +33,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
class SmartMeterTexasSensor(CoordinatorEntity, RestoreEntity, SensorEntity):
|
||||
"""Representation of an Smart Meter Texas sensor."""
|
||||
|
||||
_attr_unit_of_measurement = ENERGY_KILO_WATT_HOUR
|
||||
_attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR
|
||||
|
||||
def __init__(self, meter: Meter, coordinator: DataUpdateCoordinator) -> None:
|
||||
"""Initialize the sensor."""
|
||||
@ -58,7 +58,7 @@ class SmartMeterTexasSensor(CoordinatorEntity, RestoreEntity, SensorEntity):
|
||||
return self._available
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Get the latest reading."""
|
||||
return self._state
|
||||
|
||||
|
@ -492,7 +492,7 @@ class SmartThingsSensor(SmartThingsEntity, SensorEntity):
|
||||
return f"{self._device.device_id}.{self._attribute}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._device.status.attributes[self._attribute].value
|
||||
|
||||
@ -502,7 +502,7 @@ class SmartThingsSensor(SmartThingsEntity, SensorEntity):
|
||||
return self._device_class
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit this state is expressed in."""
|
||||
unit = self._device.status.attributes[self._attribute].unit
|
||||
return UNITS.get(unit, unit) if unit else self._default_unit
|
||||
@ -534,7 +534,7 @@ class SmartThingsThreeAxisSensor(SmartThingsEntity, SensorEntity):
|
||||
return f"{self._device.device_id}.{THREE_AXIS_NAMES[self._index]}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
three_axis = self._device.status.attributes[Attribute.three_axis].value
|
||||
try:
|
||||
|
@ -87,7 +87,7 @@ class SmartTubSensor(SmartTubSensorBase, SensorEntity):
|
||||
"""Generic class for SmartTub status sensors."""
|
||||
|
||||
@property
|
||||
def state(self) -> str:
|
||||
def native_value(self) -> str:
|
||||
"""Return the current state of the sensor."""
|
||||
if isinstance(self._state, Enum):
|
||||
return self._state.name.lower()
|
||||
@ -109,7 +109,7 @@ class SmartTubPrimaryFiltrationCycle(SmartTubSensor):
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def state(self) -> str:
|
||||
def native_value(self) -> str:
|
||||
"""Return the current state of the sensor."""
|
||||
return self.cycle.status.name.lower()
|
||||
|
||||
@ -147,7 +147,7 @@ class SmartTubSecondaryFiltrationCycle(SmartTubSensor):
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def state(self) -> str:
|
||||
def native_value(self) -> str:
|
||||
"""Return the current state of the sensor."""
|
||||
return self.cycle.status.name.lower()
|
||||
|
||||
|
@ -64,12 +64,12 @@ class SmartySensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit this state is expressed in."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
|
@ -25,7 +25,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
key="signal",
|
||||
name=f"gsm_signal_imei_{imei}",
|
||||
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||
unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
|
||||
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
)
|
||||
@ -55,7 +55,7 @@ class GSMSignalSensor(SensorEntity):
|
||||
return self._state is not None
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the device."""
|
||||
return self._state["SignalStrength"]
|
||||
|
||||
|
@ -155,12 +155,12 @@ class SnmpSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit the value is expressed in."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
|
@ -54,7 +54,7 @@ class SochainSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return (
|
||||
self.chainso.data.get("confirmed_balance")
|
||||
@ -63,7 +63,7 @@ class SochainSensor(SensorEntity):
|
||||
)
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement this sensor expresses itself in."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
|
@ -42,7 +42,7 @@ SENSOR_TYPES = [
|
||||
icon="mdi:solar-power",
|
||||
last_reset=dt_util.utc_from_timestamp(0),
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
unit_of_measurement=ENERGY_WATT_HOUR,
|
||||
native_unit_of_measurement=ENERGY_WATT_HOUR,
|
||||
device_class=DEVICE_CLASS_ENERGY,
|
||||
),
|
||||
SolarEdgeSensorEntityDescription(
|
||||
@ -51,7 +51,7 @@ SENSOR_TYPES = [
|
||||
name="Energy this year",
|
||||
entity_registry_enabled_default=False,
|
||||
icon="mdi:solar-power",
|
||||
unit_of_measurement=ENERGY_WATT_HOUR,
|
||||
native_unit_of_measurement=ENERGY_WATT_HOUR,
|
||||
device_class=DEVICE_CLASS_ENERGY,
|
||||
),
|
||||
SolarEdgeSensorEntityDescription(
|
||||
@ -60,7 +60,7 @@ SENSOR_TYPES = [
|
||||
name="Energy this month",
|
||||
entity_registry_enabled_default=False,
|
||||
icon="mdi:solar-power",
|
||||
unit_of_measurement=ENERGY_WATT_HOUR,
|
||||
native_unit_of_measurement=ENERGY_WATT_HOUR,
|
||||
device_class=DEVICE_CLASS_ENERGY,
|
||||
),
|
||||
SolarEdgeSensorEntityDescription(
|
||||
@ -69,7 +69,7 @@ SENSOR_TYPES = [
|
||||
name="Energy today",
|
||||
entity_registry_enabled_default=False,
|
||||
icon="mdi:solar-power",
|
||||
unit_of_measurement=ENERGY_WATT_HOUR,
|
||||
native_unit_of_measurement=ENERGY_WATT_HOUR,
|
||||
device_class=DEVICE_CLASS_ENERGY,
|
||||
),
|
||||
SolarEdgeSensorEntityDescription(
|
||||
@ -78,7 +78,7 @@ SENSOR_TYPES = [
|
||||
name="Current Power",
|
||||
icon="mdi:solar-power",
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
unit_of_measurement=POWER_WATT,
|
||||
native_unit_of_measurement=POWER_WATT,
|
||||
device_class=DEVICE_CLASS_POWER,
|
||||
),
|
||||
SolarEdgeSensorEntityDescription(
|
||||
@ -185,6 +185,6 @@ SENSOR_TYPES = [
|
||||
name="Storage Level",
|
||||
entity_registry_enabled_default=False,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
unit_of_measurement=PERCENTAGE,
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
),
|
||||
]
|
||||
|
@ -133,7 +133,7 @@ class SolarEdgeOverviewSensor(SolarEdgeSensorEntity):
|
||||
"""Representation of an SolarEdge Monitoring API overview sensor."""
|
||||
|
||||
@property
|
||||
def state(self) -> str | None:
|
||||
def native_value(self) -> str | None:
|
||||
"""Return the state of the sensor."""
|
||||
return self.data_service.data.get(self.entity_description.json_key)
|
||||
|
||||
@ -147,7 +147,7 @@ class SolarEdgeDetailsSensor(SolarEdgeSensorEntity):
|
||||
return self.data_service.attributes
|
||||
|
||||
@property
|
||||
def state(self) -> str | None:
|
||||
def native_value(self) -> str | None:
|
||||
"""Return the state of the sensor."""
|
||||
return self.data_service.data
|
||||
|
||||
@ -161,7 +161,7 @@ class SolarEdgeInventorySensor(SolarEdgeSensorEntity):
|
||||
return self.data_service.attributes.get(self.entity_description.json_key)
|
||||
|
||||
@property
|
||||
def state(self) -> str | None:
|
||||
def native_value(self) -> str | None:
|
||||
"""Return the state of the sensor."""
|
||||
return self.data_service.data.get(self.entity_description.json_key)
|
||||
|
||||
@ -173,7 +173,7 @@ class SolarEdgeEnergyDetailsSensor(SolarEdgeSensorEntity):
|
||||
"""Initialize the power flow sensor."""
|
||||
super().__init__(platform_name, sensor_type, data_service)
|
||||
|
||||
self._attr_unit_of_measurement = data_service.unit
|
||||
self._attr_native_unit_of_measurement = data_service.unit
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> dict[str, Any]:
|
||||
@ -181,7 +181,7 @@ class SolarEdgeEnergyDetailsSensor(SolarEdgeSensorEntity):
|
||||
return self.data_service.attributes.get(self.entity_description.json_key)
|
||||
|
||||
@property
|
||||
def state(self) -> str | None:
|
||||
def native_value(self) -> str | None:
|
||||
"""Return the state of the sensor."""
|
||||
return self.data_service.data.get(self.entity_description.json_key)
|
||||
|
||||
@ -200,7 +200,7 @@ class SolarEdgePowerFlowSensor(SolarEdgeSensorEntity):
|
||||
"""Initialize the power flow sensor."""
|
||||
super().__init__(platform_name, description, data_service)
|
||||
|
||||
self._attr_unit_of_measurement = data_service.unit
|
||||
self._attr_native_unit_of_measurement = data_service.unit
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> dict[str, Any]:
|
||||
@ -208,7 +208,7 @@ class SolarEdgePowerFlowSensor(SolarEdgeSensorEntity):
|
||||
return self.data_service.attributes.get(self.entity_description.json_key)
|
||||
|
||||
@property
|
||||
def state(self) -> str | None:
|
||||
def native_value(self) -> str | None:
|
||||
"""Return the state of the sensor."""
|
||||
return self.data_service.data.get(self.entity_description.json_key)
|
||||
|
||||
@ -219,7 +219,7 @@ class SolarEdgeStorageLevelSensor(SolarEdgeSensorEntity):
|
||||
_attr_device_class = DEVICE_CLASS_BATTERY
|
||||
|
||||
@property
|
||||
def state(self) -> str | None:
|
||||
def native_value(self) -> str | None:
|
||||
"""Return the state of the sensor."""
|
||||
attr = self.data_service.attributes.get(self.entity_description.json_key)
|
||||
if attr and "soc" in attr:
|
||||
|
@ -285,7 +285,7 @@ class SolarEdgeSensor(SensorEntity):
|
||||
return f"{self._platform_name} ({self._name})"
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
@ -305,7 +305,7 @@ class SolarEdgeSensor(SensorEntity):
|
||||
return self._icon
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
|
@ -82,7 +82,7 @@ class SolarlogSensor(SensorEntity):
|
||||
return f"{self.device_name} {self._label}"
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
@ -92,7 +92,7 @@ class SolarlogSensor(SensorEntity):
|
||||
return self._icon
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
|
@ -84,7 +84,7 @@ class Inverter(SensorEntity):
|
||||
self.unit = unit
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""State of this inverter attribute."""
|
||||
return self.value
|
||||
|
||||
@ -99,7 +99,7 @@ class Inverter(SensorEntity):
|
||||
return f"Solax {self.serial} {self.key}"
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return self.unit
|
||||
|
||||
|
@ -30,7 +30,7 @@ class SomaSensor(SomaEntity, SensorEntity):
|
||||
"""Representation of a Soma cover device."""
|
||||
|
||||
_attr_device_class = DEVICE_CLASS_BATTERY
|
||||
_attr_unit_of_measurement = PERCENTAGE
|
||||
_attr_native_unit_of_measurement = PERCENTAGE
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
@ -38,7 +38,7 @@ class SomaSensor(SomaEntity, SensorEntity):
|
||||
return self.device["name"] + " battery level"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the entity."""
|
||||
return self.battery_state
|
||||
|
||||
|
@ -30,7 +30,7 @@ class SomfyThermostatBatterySensor(SomfyEntity, SensorEntity):
|
||||
"""Representation of a Somfy thermostat battery."""
|
||||
|
||||
_attr_device_class = DEVICE_CLASS_BATTERY
|
||||
_attr_unit_of_measurement = PERCENTAGE
|
||||
_attr_native_unit_of_measurement = PERCENTAGE
|
||||
|
||||
def __init__(self, coordinator, device_id):
|
||||
"""Initialize the Somfy device."""
|
||||
@ -43,6 +43,6 @@ class SomfyThermostatBatterySensor(SomfyEntity, SensorEntity):
|
||||
self._climate = Thermostat(self.device, self.coordinator.client)
|
||||
|
||||
@property
|
||||
def state(self) -> int:
|
||||
def native_value(self) -> int:
|
||||
"""Return the state of the sensor."""
|
||||
return self._climate.get_battery()
|
||||
|
@ -85,7 +85,7 @@ class SonarrSensor(SonarrEntity, SensorEntity):
|
||||
self._attr_name = name
|
||||
self._attr_icon = icon
|
||||
self._attr_unique_id = f"{entry_id}_{key}"
|
||||
self._attr_unit_of_measurement = unit_of_measurement
|
||||
self._attr_native_unit_of_measurement = unit_of_measurement
|
||||
self._attr_entity_registry_enabled_default = enabled_default
|
||||
self.last_update_success = False
|
||||
|
||||
@ -134,7 +134,7 @@ class SonarrCommandsSensor(SonarrSensor):
|
||||
return attrs
|
||||
|
||||
@property
|
||||
def state(self) -> int:
|
||||
def native_value(self) -> int:
|
||||
"""Return the state of the sensor."""
|
||||
return len(self._commands)
|
||||
|
||||
@ -181,7 +181,7 @@ class SonarrDiskspaceSensor(SonarrSensor):
|
||||
return attrs
|
||||
|
||||
@property
|
||||
def state(self) -> str:
|
||||
def native_value(self) -> str:
|
||||
"""Return the state of the sensor."""
|
||||
free = self._total_free / 1024 ** 3
|
||||
return f"{free:.2f}"
|
||||
@ -223,7 +223,7 @@ class SonarrQueueSensor(SonarrSensor):
|
||||
return attrs
|
||||
|
||||
@property
|
||||
def state(self) -> int:
|
||||
def native_value(self) -> int:
|
||||
"""Return the state of the sensor."""
|
||||
return len(self._queue)
|
||||
|
||||
@ -261,7 +261,7 @@ class SonarrSeriesSensor(SonarrSensor):
|
||||
return attrs
|
||||
|
||||
@property
|
||||
def state(self) -> int:
|
||||
def native_value(self) -> int:
|
||||
"""Return the state of the sensor."""
|
||||
return len(self._items)
|
||||
|
||||
@ -304,7 +304,7 @@ class SonarrUpcomingSensor(SonarrSensor):
|
||||
return attrs
|
||||
|
||||
@property
|
||||
def state(self) -> int:
|
||||
def native_value(self) -> int:
|
||||
"""Return the state of the sensor."""
|
||||
return len(self._upcoming)
|
||||
|
||||
@ -347,6 +347,6 @@ class SonarrWantedSensor(SonarrSensor):
|
||||
return attrs
|
||||
|
||||
@property
|
||||
def state(self) -> int | None:
|
||||
def native_value(self) -> int | None:
|
||||
"""Return the state of the sensor."""
|
||||
return self._total
|
||||
|
@ -45,7 +45,7 @@ class SonosBatteryEntity(SonosEntity, SensorEntity):
|
||||
return DEVICE_CLASS_BATTERY
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self) -> str:
|
||||
def native_unit_of_measurement(self) -> str:
|
||||
"""Get the unit of measurement."""
|
||||
return PERCENTAGE
|
||||
|
||||
@ -54,7 +54,7 @@ class SonosBatteryEntity(SonosEntity, SensorEntity):
|
||||
await self.speaker.async_poll_battery()
|
||||
|
||||
@property
|
||||
def state(self) -> int | None:
|
||||
def native_value(self) -> int | None:
|
||||
"""Return the state of the sensor."""
|
||||
return self.speaker.battery_info.get("Level")
|
||||
|
||||
|
@ -17,19 +17,19 @@ SENSOR_TYPES: Final[tuple[SensorEntityDescription, ...]] = (
|
||||
SensorEntityDescription(
|
||||
key="ping",
|
||||
name="Ping",
|
||||
unit_of_measurement=TIME_MILLISECONDS,
|
||||
native_unit_of_measurement=TIME_MILLISECONDS,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="download",
|
||||
name="Download",
|
||||
unit_of_measurement=DATA_RATE_MEGABITS_PER_SECOND,
|
||||
native_unit_of_measurement=DATA_RATE_MEGABITS_PER_SECOND,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="upload",
|
||||
name="Upload",
|
||||
unit_of_measurement=DATA_RATE_MEGABITS_PER_SECOND,
|
||||
native_unit_of_measurement=DATA_RATE_MEGABITS_PER_SECOND,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
)
|
||||
|
@ -85,7 +85,7 @@ class SpeedtestSensor(CoordinatorEntity, RestoreEntity, SensorEntity):
|
||||
await super().async_added_to_hass()
|
||||
state = await self.async_get_last_state()
|
||||
if state:
|
||||
self._attr_state = state.state
|
||||
self._attr_native_value = state.state
|
||||
|
||||
@callback
|
||||
def update() -> None:
|
||||
@ -100,8 +100,12 @@ class SpeedtestSensor(CoordinatorEntity, RestoreEntity, SensorEntity):
|
||||
"""Update sensors state."""
|
||||
if self.coordinator.data:
|
||||
if self.entity_description.key == "ping":
|
||||
self._attr_state = self.coordinator.data["ping"]
|
||||
self._attr_native_value = self.coordinator.data["ping"]
|
||||
elif self.entity_description.key == "download":
|
||||
self._attr_state = round(self.coordinator.data["download"] / 10 ** 6, 2)
|
||||
self._attr_native_value = round(
|
||||
self.coordinator.data["download"] / 10 ** 6, 2
|
||||
)
|
||||
elif self.entity_description.key == "upload":
|
||||
self._attr_state = round(self.coordinator.data["upload"] / 10 ** 6, 2)
|
||||
self._attr_native_value = round(
|
||||
self.coordinator.data["upload"] / 10 ** 6, 2
|
||||
)
|
||||
|
@ -123,12 +123,12 @@ class SQLSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the query's current state."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
|
@ -93,14 +93,14 @@ class SrpEntity(SensorEntity):
|
||||
return self.type
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the device."""
|
||||
if self._state:
|
||||
return f"{self._state:.2f}"
|
||||
return None
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement of this entity, if any."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
|
@ -21,15 +21,17 @@ async def test_setup(hass, requests_mock):
|
||||
assert len(devices) == 2
|
||||
|
||||
left_side = devices[1]
|
||||
left_side.hass = hass
|
||||
assert left_side.name == "SleepNumber ILE Test1 SleepNumber"
|
||||
assert left_side.state == 40
|
||||
|
||||
right_side = devices[0]
|
||||
right_side.hass = hass
|
||||
assert right_side.name == "SleepNumber ILE Test2 SleepNumber"
|
||||
assert right_side.state == 80
|
||||
|
||||
|
||||
async def test_setup_sigle(hass, requests_mock):
|
||||
async def test_setup_single(hass, requests_mock):
|
||||
"""Test for successfully setting up the SleepIQ platform."""
|
||||
mock_responses(requests_mock, single=True)
|
||||
|
||||
@ -41,5 +43,6 @@ async def test_setup_sigle(hass, requests_mock):
|
||||
assert len(devices) == 1
|
||||
|
||||
right_side = devices[0]
|
||||
right_side.hass = hass
|
||||
assert right_side.name == "SleepNumber ILE Test1 SleepNumber"
|
||||
assert right_side.state == 40
|
||||
|
@ -82,6 +82,7 @@ async def test_srp_entity(hass):
|
||||
"""Test the SrpEntity."""
|
||||
fake_coordinator = MagicMock(data=1.99999999999)
|
||||
srp_entity = SrpEntity(fake_coordinator)
|
||||
srp_entity.hass = hass
|
||||
|
||||
assert srp_entity is not None
|
||||
assert srp_entity.name == f"{DEFAULT_NAME} {SENSOR_NAME}"
|
||||
@ -104,6 +105,7 @@ async def test_srp_entity_no_data(hass):
|
||||
"""Test the SrpEntity."""
|
||||
fake_coordinator = MagicMock(data=False)
|
||||
srp_entity = SrpEntity(fake_coordinator)
|
||||
srp_entity.hass = hass
|
||||
assert srp_entity.extra_state_attributes is None
|
||||
|
||||
|
||||
@ -111,6 +113,7 @@ async def test_srp_entity_no_coord_data(hass):
|
||||
"""Test the SrpEntity."""
|
||||
fake_coordinator = MagicMock(data=False)
|
||||
srp_entity = SrpEntity(fake_coordinator)
|
||||
srp_entity.hass = hass
|
||||
|
||||
assert srp_entity.usage is None
|
||||
|
||||
@ -124,6 +127,7 @@ async def test_srp_entity_async_update(hass):
|
||||
MagicMock.__await__ = lambda x: async_magic().__await__()
|
||||
fake_coordinator = MagicMock(data=False)
|
||||
srp_entity = SrpEntity(fake_coordinator)
|
||||
srp_entity.hass = hass
|
||||
|
||||
await srp_entity.async_update()
|
||||
assert fake_coordinator.async_request_refresh.called
|
||||
|
Loading…
x
Reference in New Issue
Block a user