mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
Move temperature conversions to entity base class (7/8) (#54482)
This commit is contained in:
parent
41f3c2766c
commit
94a264afaf
@ -69,7 +69,7 @@ class StarlineSensor(StarlineEntity, SensorEntity):
|
||||
return self._icon
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
if self._key == "battery":
|
||||
return self._device.battery_level
|
||||
@ -90,7 +90,7 @@ class StarlineSensor(StarlineEntity, SensorEntity):
|
||||
return None
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Get the unit of measurement."""
|
||||
if self._key == "balance":
|
||||
return self._device.balance.get("currency") or "₽"
|
||||
|
@ -79,12 +79,12 @@ class StarlingBalanceSensor(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."""
|
||||
return self._starling_account.currency
|
||||
|
||||
|
@ -93,12 +93,12 @@ class StartcaSensor(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
|
||||
|
||||
@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
|
||||
|
||||
|
@ -203,12 +203,12 @@ class StatisticsSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self.mean if not self.is_binary else self.count
|
||||
|
||||
@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 if not self.is_binary else None
|
||||
|
||||
|
@ -99,7 +99,7 @@ class SteamSensor(SensorEntity):
|
||||
return f"sensor.steam_{self._account}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
|
@ -87,12 +87,12 @@ class StreamLabsDailyUsage(SensorEntity):
|
||||
return WATER_ICON
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the current daily usage."""
|
||||
return self._streamlabs_usage_data.get_daily_usage()
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return gallons as the unit measurement for water."""
|
||||
return VOLUME_GALLONS
|
||||
|
||||
@ -110,7 +110,7 @@ class StreamLabsMonthlyUsage(StreamLabsDailyUsage):
|
||||
return f"{self._location_name} {NAME_MONTHLY_USAGE}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the current monthly usage."""
|
||||
return self._streamlabs_usage_data.get_monthly_usage()
|
||||
|
||||
@ -124,6 +124,6 @@ class StreamLabsYearlyUsage(StreamLabsDailyUsage):
|
||||
return f"{self._location_name} {NAME_YEARLY_USAGE}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the current yearly usage."""
|
||||
return self._streamlabs_usage_data.get_yearly_usage()
|
||||
|
@ -203,7 +203,7 @@ class SubaruSensor(SubaruEntity, SensorEntity):
|
||||
return None
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
self.current_value = self.get_current_value()
|
||||
|
||||
@ -238,7 +238,7 @@ class SubaruSensor(SubaruEntity, SensorEntity):
|
||||
return self.current_value
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit_of_measurement of the device."""
|
||||
if self.api_unit in TEMPERATURE_UNITS:
|
||||
return self.hass.config.units.temperature_unit
|
||||
|
@ -62,12 +62,12 @@ class SuezSensor(SensorEntity):
|
||||
return COMPONENT_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 VOLUME_LITERS
|
||||
|
||||
|
@ -50,7 +50,7 @@ class SupervisorProcessSensor(SensorEntity):
|
||||
return self._info.get("name")
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._info.get("statename")
|
||||
|
||||
|
@ -60,7 +60,7 @@ class SureBattery(SensorEntity):
|
||||
|
||||
self._attr_device_class = DEVICE_CLASS_BATTERY
|
||||
self._attr_name = f"{surepy_entity.type.name.capitalize()} {surepy_entity.name.capitalize()} Battery Level"
|
||||
self._attr_unit_of_measurement = PERCENTAGE
|
||||
self._attr_native_unit_of_measurement = PERCENTAGE
|
||||
self._attr_unique_id = (
|
||||
f"{surepy_entity.household_id}-{surepy_entity.id}-battery"
|
||||
)
|
||||
@ -75,11 +75,11 @@ class SureBattery(SensorEntity):
|
||||
try:
|
||||
per_battery_voltage = state["battery"] / 4
|
||||
voltage_diff = per_battery_voltage - SURE_BATT_VOLTAGE_LOW
|
||||
self._attr_state = min(
|
||||
self._attr_native_value = min(
|
||||
int(voltage_diff / SURE_BATT_VOLTAGE_DIFF * 100), 100
|
||||
)
|
||||
except (KeyError, TypeError):
|
||||
self._attr_state = None
|
||||
self._attr_native_value = None
|
||||
|
||||
if state:
|
||||
voltage_per_battery = float(state["battery"]) / 4
|
||||
|
@ -94,14 +94,14 @@ class SwissHydrologicalDataSensor(SensorEntity):
|
||||
return f"{self._station}_{self._condition}"
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement of this entity, if any."""
|
||||
if self._state is not None:
|
||||
return self.hydro_data.data["parameters"][self._condition]["unit"]
|
||||
return None
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
if isinstance(self._state, (int, float)):
|
||||
return round(self._state, 2)
|
||||
|
@ -84,7 +84,7 @@ class SwissPublicTransportSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return (
|
||||
self._opendata.connections[0]["departure"]
|
||||
|
@ -110,7 +110,7 @@ class SwitcherSensorEntity(CoordinatorEntity, SensorEntity):
|
||||
# Entity class attributes
|
||||
self._attr_name = f"{wrapper.name} {description.name}"
|
||||
self._attr_icon = description.icon
|
||||
self._attr_unit_of_measurement = description.unit
|
||||
self._attr_native_unit_of_measurement = description.unit
|
||||
self._attr_device_class = description.device_class
|
||||
self._attr_entity_registry_enabled_default = description.default_enabled
|
||||
|
||||
@ -122,6 +122,6 @@ class SwitcherSensorEntity(CoordinatorEntity, SensorEntity):
|
||||
}
|
||||
|
||||
@property
|
||||
def state(self) -> StateType:
|
||||
def native_value(self) -> StateType:
|
||||
"""Return value of sensor."""
|
||||
return getattr(self.wrapper.data, self.attribute) # type: ignore[no-any-return]
|
||||
|
@ -105,7 +105,7 @@ class FolderSensor(SensorEntity):
|
||||
return f"{self._short_server_id}-{self._folder_id}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state["state"]
|
||||
|
||||
|
@ -124,7 +124,7 @@ class SyncThruSensor(CoordinatorEntity, SensorEntity):
|
||||
return self._icon
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measuremnt."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
@ -148,7 +148,7 @@ class SyncThruMainSensor(SyncThruSensor):
|
||||
self._id_suffix = "_main"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Set state to human readable version of syncthru status."""
|
||||
return SYNCTHRU_STATE_HUMAN[self.syncthru.device_status()]
|
||||
|
||||
@ -182,7 +182,7 @@ class SyncThruTonerSensor(SyncThruSensor):
|
||||
return self.syncthru.toner_status().get(self._color, {})
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Show amount of remaining toner."""
|
||||
return self.syncthru.toner_status().get(self._color, {}).get("remaining")
|
||||
|
||||
@ -204,7 +204,7 @@ class SyncThruDrumSensor(SyncThruSensor):
|
||||
return self.syncthru.drum_status().get(self._color, {})
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Show amount of remaining drum."""
|
||||
return self.syncthru.drum_status().get(self._color, {}).get("remaining")
|
||||
|
||||
@ -225,7 +225,7 @@ class SyncThruInputTraySensor(SyncThruSensor):
|
||||
return self.syncthru.input_tray_status().get(self._number, {})
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Display ready unless there is some error, then display error."""
|
||||
tray_state = (
|
||||
self.syncthru.input_tray_status().get(self._number, {}).get("newError")
|
||||
@ -251,7 +251,7 @@ class SyncThruOutputTraySensor(SyncThruSensor):
|
||||
return self.syncthru.output_tray_status().get(self._number, {})
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Display ready unless there is some error, then display error."""
|
||||
tray_state = (
|
||||
self.syncthru.output_tray_status().get(self._number, {}).get("status")
|
||||
|
@ -90,7 +90,7 @@ class SynoDSMSensor(SynologyDSMBaseEntity):
|
||||
"""Mixin for sensor specific attributes."""
|
||||
|
||||
@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 self.entity_type in TEMP_SENSORS_KEYS:
|
||||
return self.hass.config.units.temperature_unit
|
||||
@ -101,7 +101,7 @@ class SynoDSMUtilSensor(SynoDSMSensor, SensorEntity):
|
||||
"""Representation a Synology Utilisation sensor."""
|
||||
|
||||
@property
|
||||
def state(self) -> Any | None:
|
||||
def native_value(self) -> Any | None:
|
||||
"""Return the state."""
|
||||
attr = getattr(self._api.utilisation, self.entity_type)
|
||||
if callable(attr):
|
||||
@ -133,7 +133,7 @@ class SynoDSMStorageSensor(SynologyDSMDeviceEntity, SynoDSMSensor, SensorEntity)
|
||||
"""Representation a Synology Storage sensor."""
|
||||
|
||||
@property
|
||||
def state(self) -> Any | None:
|
||||
def native_value(self) -> Any | None:
|
||||
"""Return the state."""
|
||||
attr = getattr(self._api.storage, self.entity_type)(self._device_id)
|
||||
if attr is None:
|
||||
@ -166,7 +166,7 @@ class SynoDSMInfoSensor(SynoDSMSensor, SensorEntity):
|
||||
self._last_boot: str | None = None
|
||||
|
||||
@property
|
||||
def state(self) -> Any | None:
|
||||
def native_value(self) -> Any | None:
|
||||
"""Return the state."""
|
||||
attr = getattr(self._api.information, self.entity_type)
|
||||
if attr is None:
|
||||
|
@ -92,7 +92,7 @@ class SystemBridgeSensor(SystemBridgeDeviceEntity, SensorEntity):
|
||||
return self._device_class
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self) -> str | None:
|
||||
def native_unit_of_measurement(self) -> str | None:
|
||||
"""Return the unit this state is expressed in."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
@ -113,7 +113,7 @@ class SystemBridgeBatterySensor(SystemBridgeSensor):
|
||||
)
|
||||
|
||||
@property
|
||||
def state(self) -> float:
|
||||
def native_value(self) -> float:
|
||||
"""Return the state of the sensor."""
|
||||
bridge: Bridge = self.coordinator.data
|
||||
return bridge.battery.percent
|
||||
@ -135,7 +135,7 @@ class SystemBridgeBatteryTimeRemainingSensor(SystemBridgeSensor):
|
||||
)
|
||||
|
||||
@property
|
||||
def state(self) -> str | None:
|
||||
def native_value(self) -> str | None:
|
||||
"""Return the state of the sensor."""
|
||||
bridge: Bridge = self.coordinator.data
|
||||
if bridge.battery.timeRemaining is None:
|
||||
@ -159,7 +159,7 @@ class SystemBridgeCpuSpeedSensor(SystemBridgeSensor):
|
||||
)
|
||||
|
||||
@property
|
||||
def state(self) -> float:
|
||||
def native_value(self) -> float:
|
||||
"""Return the state of the sensor."""
|
||||
bridge: Bridge = self.coordinator.data
|
||||
return bridge.cpu.currentSpeed.avg
|
||||
@ -181,7 +181,7 @@ class SystemBridgeCpuTemperatureSensor(SystemBridgeSensor):
|
||||
)
|
||||
|
||||
@property
|
||||
def state(self) -> float:
|
||||
def native_value(self) -> float:
|
||||
"""Return the state of the sensor."""
|
||||
bridge: Bridge = self.coordinator.data
|
||||
return bridge.cpu.temperature.main
|
||||
@ -203,7 +203,7 @@ class SystemBridgeCpuVoltageSensor(SystemBridgeSensor):
|
||||
)
|
||||
|
||||
@property
|
||||
def state(self) -> float:
|
||||
def native_value(self) -> float:
|
||||
"""Return the state of the sensor."""
|
||||
bridge: Bridge = self.coordinator.data
|
||||
return bridge.cpu.cpu.voltage
|
||||
@ -229,7 +229,7 @@ class SystemBridgeFilesystemSensor(SystemBridgeSensor):
|
||||
self._fs_key = key
|
||||
|
||||
@property
|
||||
def state(self) -> float:
|
||||
def native_value(self) -> float:
|
||||
"""Return the state of the sensor."""
|
||||
bridge: Bridge = self.coordinator.data
|
||||
return (
|
||||
@ -268,7 +268,7 @@ class SystemBridgeMemoryFreeSensor(SystemBridgeSensor):
|
||||
)
|
||||
|
||||
@property
|
||||
def state(self) -> float | None:
|
||||
def native_value(self) -> float | None:
|
||||
"""Return the state of the sensor."""
|
||||
bridge: Bridge = self.coordinator.data
|
||||
return (
|
||||
@ -294,7 +294,7 @@ class SystemBridgeMemoryUsedSensor(SystemBridgeSensor):
|
||||
)
|
||||
|
||||
@property
|
||||
def state(self) -> str | None:
|
||||
def native_value(self) -> str | None:
|
||||
"""Return the state of the sensor."""
|
||||
bridge: Bridge = self.coordinator.data
|
||||
return (
|
||||
@ -320,7 +320,7 @@ class SystemBridgeMemoryUsedPercentageSensor(SystemBridgeSensor):
|
||||
)
|
||||
|
||||
@property
|
||||
def state(self) -> str | None:
|
||||
def native_value(self) -> str | None:
|
||||
"""Return the state of the sensor."""
|
||||
bridge: Bridge = self.coordinator.data
|
||||
return (
|
||||
@ -346,7 +346,7 @@ class SystemBridgeKernelSensor(SystemBridgeSensor):
|
||||
)
|
||||
|
||||
@property
|
||||
def state(self) -> str:
|
||||
def native_value(self) -> str:
|
||||
"""Return the state of the sensor."""
|
||||
bridge: Bridge = self.coordinator.data
|
||||
return bridge.os.kernel
|
||||
@ -368,7 +368,7 @@ class SystemBridgeOsSensor(SystemBridgeSensor):
|
||||
)
|
||||
|
||||
@property
|
||||
def state(self) -> str:
|
||||
def native_value(self) -> str:
|
||||
"""Return the state of the sensor."""
|
||||
bridge: Bridge = self.coordinator.data
|
||||
return f"{bridge.os.distro} {bridge.os.release}"
|
||||
@ -390,7 +390,7 @@ class SystemBridgeProcessesLoadSensor(SystemBridgeSensor):
|
||||
)
|
||||
|
||||
@property
|
||||
def state(self) -> float | None:
|
||||
def native_value(self) -> float | None:
|
||||
"""Return the state of the sensor."""
|
||||
bridge: Bridge = self.coordinator.data
|
||||
return (
|
||||
@ -431,7 +431,7 @@ class SystemBridgeBiosVersionSensor(SystemBridgeSensor):
|
||||
)
|
||||
|
||||
@property
|
||||
def state(self) -> str:
|
||||
def native_value(self) -> str:
|
||||
"""Return the state of the sensor."""
|
||||
bridge: Bridge = self.coordinator.data
|
||||
return bridge.system.bios.version
|
||||
|
@ -331,12 +331,12 @@ class SystemMonitorSensor(SensorEntity):
|
||||
return self.sensor_type[SENSOR_TYPE_ICON] # type: ignore[no-any-return]
|
||||
|
||||
@property
|
||||
def state(self) -> str | None:
|
||||
def native_value(self) -> str | None:
|
||||
"""Return the state of the device."""
|
||||
return self.data.state
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self) -> str | None:
|
||||
def native_unit_of_measurement(self) -> str | None:
|
||||
"""Return the unit of measurement of this entity, if any."""
|
||||
return self.sensor_type[SENSOR_TYPE_UOM] # type: ignore[no-any-return]
|
||||
|
||||
|
@ -127,7 +127,7 @@ class TadoHomeSensor(TadoHomeEntity, SensorEntity):
|
||||
return f"{self._tado.home_name} {self.home_variable}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@ -137,7 +137,7 @@ class TadoHomeSensor(TadoHomeEntity, SensorEntity):
|
||||
return self._state_attributes
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
if self.home_variable in ["temperature", "outdoor temperature"]:
|
||||
return TEMP_CELSIUS
|
||||
@ -232,7 +232,7 @@ class TadoZoneSensor(TadoZoneEntity, SensorEntity):
|
||||
return f"{self.zone_name} {self.zone_variable}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@ -242,7 +242,7 @@ class TadoZoneSensor(TadoZoneEntity, SensorEntity):
|
||||
return self._state_attributes
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
if self.zone_variable == "temperature":
|
||||
return self.hass.config.units.temperature_unit
|
||||
|
@ -35,12 +35,12 @@ class TahomaSensor(TahomaDevice, SensorEntity):
|
||||
super().__init__(tahoma_device, controller)
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the name of the sensor."""
|
||||
return self.current_value
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement of this entity, if any."""
|
||||
if self.tahoma_device.type == "io:TemperatureIOSystemSensor":
|
||||
return TEMP_CELSIUS
|
||||
|
@ -81,7 +81,7 @@ class TankUtilitySensor(SensorEntity):
|
||||
return self._device
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the device."""
|
||||
return self._state
|
||||
|
||||
@ -91,7 +91,7 @@ class TankUtilitySensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement of the device."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
|
@ -110,12 +110,12 @@ class FuelPriceSensor(CoordinatorEntity, SensorEntity):
|
||||
return ICON
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return unit of measurement."""
|
||||
return CURRENCY_EURO
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the device."""
|
||||
# key Fuel_type is not available when the fuel station is closed, use "get" instead of "[]" to avoid exceptions
|
||||
return self.coordinator.data[self._station_id].get(self._fuel_type)
|
||||
|
@ -258,7 +258,7 @@ class TasmotaSensor(TasmotaAvailability, TasmotaDiscoveryUpdate, SensorEntity):
|
||||
return class_or_icon.get(ICON)
|
||||
|
||||
@property
|
||||
def state(self) -> str | None:
|
||||
def native_value(self) -> str | None:
|
||||
"""Return the state of the entity."""
|
||||
if self._state_timestamp and self.device_class == DEVICE_CLASS_TIMESTAMP:
|
||||
return self._state_timestamp.isoformat()
|
||||
@ -270,6 +270,6 @@ class TasmotaSensor(TasmotaAvailability, TasmotaDiscoveryUpdate, SensorEntity):
|
||||
return True
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self) -> str | None:
|
||||
def native_unit_of_measurement(self) -> str | None:
|
||||
"""Return the unit this state is expressed in."""
|
||||
return SENSOR_UNIT_MAP.get(self._tasmota_entity.unit, self._tasmota_entity.unit)
|
||||
|
@ -114,7 +114,7 @@ class TautulliSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self.sessions.get("stream_count")
|
||||
|
||||
@ -124,7 +124,7 @@ class TautulliSensor(SensorEntity):
|
||||
return "mdi:plex"
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit this state is expressed in."""
|
||||
return "Watching"
|
||||
|
||||
|
@ -31,11 +31,11 @@ class TcpSensor(TcpEntity, SensorEntity):
|
||||
"""Implementation of a TCP socket based sensor."""
|
||||
|
||||
@property
|
||||
def state(self) -> StateType:
|
||||
def native_value(self) -> StateType:
|
||||
"""Return the state of the device."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self) -> str | None:
|
||||
def native_unit_of_measurement(self) -> str | None:
|
||||
"""Return the unit of measurement of this entity."""
|
||||
return self._config[CONF_UNIT_OF_MEASUREMENT]
|
||||
|
@ -79,12 +79,12 @@ class Ted5000Sensor(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
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the resources."""
|
||||
with suppress(KeyError):
|
||||
return self._gateway.data[self._mtu][self._unit]
|
||||
|
@ -111,7 +111,7 @@ class TelldusLiveSensor(TelldusLiveEntity, SensorEntity):
|
||||
return "{} {}".format(super().name, self.quantity_name or "").strip()
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
if not self.available:
|
||||
return None
|
||||
@ -129,7 +129,7 @@ class TelldusLiveSensor(TelldusLiveEntity, SensorEntity):
|
||||
return SENSOR_TYPES[self._type][0] if self._type in SENSOR_TYPES else None
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return SENSOR_TYPES[self._type][1] if self._type in SENSOR_TYPES else None
|
||||
|
||||
|
@ -154,12 +154,12 @@ class TellstickSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._value
|
||||
|
||||
@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
|
||||
|
||||
|
@ -77,12 +77,12 @@ class TemperSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the entity."""
|
||||
return self.current_value
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement of this entity, if any."""
|
||||
return self.temp_unit
|
||||
|
||||
|
@ -255,7 +255,7 @@ class SensorTemplate(TemplateEntity, SensorEntity):
|
||||
except template.TemplateError:
|
||||
pass
|
||||
|
||||
self._attr_unit_of_measurement = unit_of_measurement
|
||||
self._attr_native_unit_of_measurement = unit_of_measurement
|
||||
self._template = state_template
|
||||
self._attr_device_class = device_class
|
||||
self._attr_state_class = state_class
|
||||
@ -264,7 +264,7 @@ class SensorTemplate(TemplateEntity, SensorEntity):
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
self.add_template_attribute(
|
||||
"_attr_state", self._template, None, self._update_state
|
||||
"_attr_native_value", self._template, None, self._update_state
|
||||
)
|
||||
if self._friendly_name_template and not self._friendly_name_template.is_static:
|
||||
self.add_template_attribute("_attr_name", self._friendly_name_template)
|
||||
@ -274,7 +274,7 @@ class SensorTemplate(TemplateEntity, SensorEntity):
|
||||
@callback
|
||||
def _update_state(self, result):
|
||||
super()._update_state(result)
|
||||
self._attr_state = None if isinstance(result, TemplateError) else result
|
||||
self._attr_native_value = None if isinstance(result, TemplateError) else result
|
||||
|
||||
|
||||
class TriggerSensorEntity(TriggerEntity, SensorEntity):
|
||||
@ -284,7 +284,7 @@ class TriggerSensorEntity(TriggerEntity, SensorEntity):
|
||||
extra_template_keys = (CONF_STATE,)
|
||||
|
||||
@property
|
||||
def state(self) -> str | None:
|
||||
def native_value(self) -> str | None:
|
||||
"""Return state of the sensor."""
|
||||
return self._rendered.get(CONF_STATE)
|
||||
|
||||
|
@ -38,7 +38,7 @@ class TeslaSensor(TeslaDevice, SensorEntity):
|
||||
self._unique_id = f"{super().unique_id}_{self.type}"
|
||||
|
||||
@property
|
||||
def state(self) -> float | None:
|
||||
def native_value(self) -> float | None:
|
||||
"""Return the state of the sensor."""
|
||||
if self.tesla_device.type == "temperature sensor":
|
||||
if self.type == "outside":
|
||||
@ -57,7 +57,7 @@ class TeslaSensor(TeslaDevice, SensorEntity):
|
||||
return self.tesla_device.get_value()
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self) -> str | None:
|
||||
def native_unit_of_measurement(self) -> str | None:
|
||||
"""Return the unit_of_measurement of the device."""
|
||||
units = self.tesla_device.measurement
|
||||
if units == "F":
|
||||
|
@ -120,7 +120,7 @@ class ThermoworksSmokeSensor(SensorEntity):
|
||||
return self._unique_id
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@ -130,7 +130,7 @@ class ThermoworksSmokeSensor(SensorEntity):
|
||||
return self._attributes
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement of this sensor."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
|
@ -76,7 +76,7 @@ class TtnDataSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the entity."""
|
||||
if self._ttn_data_storage.data is not None:
|
||||
try:
|
||||
@ -86,7 +86,7 @@ class TtnDataSensor(SensorEntity):
|
||||
return None
|
||||
|
||||
@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
|
||||
|
||||
|
@ -95,12 +95,12 @@ class ThinkingCleanerSensor(SensorEntity):
|
||||
return SENSOR_TYPES[self.type][2]
|
||||
|
||||
@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
|
||||
|
||||
|
@ -71,39 +71,39 @@ RT_SENSOR_MAP: dict[str, TibberSensorEntityDescription] = {
|
||||
key="averagePower",
|
||||
name="average power",
|
||||
device_class=DEVICE_CLASS_POWER,
|
||||
unit_of_measurement=POWER_WATT,
|
||||
native_unit_of_measurement=POWER_WATT,
|
||||
),
|
||||
"power": TibberSensorEntityDescription(
|
||||
key="power",
|
||||
name="power",
|
||||
device_class=DEVICE_CLASS_POWER,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
unit_of_measurement=POWER_WATT,
|
||||
native_unit_of_measurement=POWER_WATT,
|
||||
),
|
||||
"powerProduction": TibberSensorEntityDescription(
|
||||
key="powerProduction",
|
||||
name="power production",
|
||||
device_class=DEVICE_CLASS_POWER,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
unit_of_measurement=POWER_WATT,
|
||||
native_unit_of_measurement=POWER_WATT,
|
||||
),
|
||||
"minPower": TibberSensorEntityDescription(
|
||||
key="minPower",
|
||||
name="min power",
|
||||
device_class=DEVICE_CLASS_POWER,
|
||||
unit_of_measurement=POWER_WATT,
|
||||
native_unit_of_measurement=POWER_WATT,
|
||||
),
|
||||
"maxPower": TibberSensorEntityDescription(
|
||||
key="maxPower",
|
||||
name="max power",
|
||||
device_class=DEVICE_CLASS_POWER,
|
||||
unit_of_measurement=POWER_WATT,
|
||||
native_unit_of_measurement=POWER_WATT,
|
||||
),
|
||||
"accumulatedConsumption": TibberSensorEntityDescription(
|
||||
key="accumulatedConsumption",
|
||||
name="accumulated consumption",
|
||||
device_class=DEVICE_CLASS_ENERGY,
|
||||
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
reset_type=ResetType.DAILY,
|
||||
),
|
||||
@ -111,7 +111,7 @@ RT_SENSOR_MAP: dict[str, TibberSensorEntityDescription] = {
|
||||
key="accumulatedConsumptionLastHour",
|
||||
name="accumulated consumption current hour",
|
||||
device_class=DEVICE_CLASS_ENERGY,
|
||||
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
reset_type=ResetType.HOURLY,
|
||||
),
|
||||
@ -119,7 +119,7 @@ RT_SENSOR_MAP: dict[str, TibberSensorEntityDescription] = {
|
||||
key="accumulatedProduction",
|
||||
name="accumulated production",
|
||||
device_class=DEVICE_CLASS_ENERGY,
|
||||
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
reset_type=ResetType.DAILY,
|
||||
),
|
||||
@ -127,7 +127,7 @@ RT_SENSOR_MAP: dict[str, TibberSensorEntityDescription] = {
|
||||
key="accumulatedProductionLastHour",
|
||||
name="accumulated production current hour",
|
||||
device_class=DEVICE_CLASS_ENERGY,
|
||||
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
reset_type=ResetType.HOURLY,
|
||||
),
|
||||
@ -135,63 +135,63 @@ RT_SENSOR_MAP: dict[str, TibberSensorEntityDescription] = {
|
||||
key="lastMeterConsumption",
|
||||
name="last meter consumption",
|
||||
device_class=DEVICE_CLASS_ENERGY,
|
||||
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
"lastMeterProduction": TibberSensorEntityDescription(
|
||||
key="lastMeterProduction",
|
||||
name="last meter production",
|
||||
device_class=DEVICE_CLASS_ENERGY,
|
||||
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
"voltagePhase1": TibberSensorEntityDescription(
|
||||
key="voltagePhase1",
|
||||
name="voltage phase1",
|
||||
device_class=DEVICE_CLASS_VOLTAGE,
|
||||
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
"voltagePhase2": TibberSensorEntityDescription(
|
||||
key="voltagePhase2",
|
||||
name="voltage phase2",
|
||||
device_class=DEVICE_CLASS_VOLTAGE,
|
||||
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
"voltagePhase3": TibberSensorEntityDescription(
|
||||
key="voltagePhase3",
|
||||
name="voltage phase3",
|
||||
device_class=DEVICE_CLASS_VOLTAGE,
|
||||
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
"currentL1": TibberSensorEntityDescription(
|
||||
key="currentL1",
|
||||
name="current L1",
|
||||
device_class=DEVICE_CLASS_CURRENT,
|
||||
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
"currentL2": TibberSensorEntityDescription(
|
||||
key="currentL2",
|
||||
name="current L2",
|
||||
device_class=DEVICE_CLASS_CURRENT,
|
||||
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
"currentL3": TibberSensorEntityDescription(
|
||||
key="currentL3",
|
||||
name="current L3",
|
||||
device_class=DEVICE_CLASS_CURRENT,
|
||||
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
"signalStrength": TibberSensorEntityDescription(
|
||||
key="signalStrength",
|
||||
name="signal strength",
|
||||
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||
unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
|
||||
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
"accumulatedReward": TibberSensorEntityDescription(
|
||||
@ -212,7 +212,7 @@ RT_SENSOR_MAP: dict[str, TibberSensorEntityDescription] = {
|
||||
key="powerFactor",
|
||||
name="power factor",
|
||||
device_class=DEVICE_CLASS_POWER_FACTOR,
|
||||
unit_of_measurement=PERCENTAGE,
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
}
|
||||
@ -350,13 +350,13 @@ class TibberSensorElPrice(TibberSensor):
|
||||
return
|
||||
|
||||
res = self._tibber_home.current_price_data()
|
||||
self._attr_state, price_level, self._last_updated = res
|
||||
self._attr_native_value, price_level, self._last_updated = res
|
||||
self._attr_extra_state_attributes["price_level"] = price_level
|
||||
|
||||
attrs = self._tibber_home.current_attributes()
|
||||
self._attr_extra_state_attributes.update(attrs)
|
||||
self._attr_available = self._attr_state is not None
|
||||
self._attr_unit_of_measurement = self._tibber_home.price_unit
|
||||
self._attr_available = self._attr_native_value is not None
|
||||
self._attr_native_unit_of_measurement = self._tibber_home.price_unit
|
||||
|
||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||
async def _fetch_data(self):
|
||||
@ -394,11 +394,11 @@ class TibberSensorRT(TibberSensor):
|
||||
self._device_name = f"{self._model} {self._home_name}"
|
||||
|
||||
self._attr_name = f"{description.name} {self._home_name}"
|
||||
self._attr_state = initial_state
|
||||
self._attr_native_value = initial_state
|
||||
self._attr_unique_id = f"{self._tibber_home.home_id}_rt_{description.name}"
|
||||
|
||||
if description.name in ("accumulated cost", "accumulated reward"):
|
||||
self._attr_unit_of_measurement = tibber_home.currency
|
||||
self._attr_native_unit_of_measurement = tibber_home.currency
|
||||
if description.reset_type == ResetType.NEVER:
|
||||
self._attr_last_reset = dt_util.utc_from_timestamp(0)
|
||||
elif description.reset_type == ResetType.DAILY:
|
||||
@ -431,20 +431,20 @@ class TibberSensorRT(TibberSensor):
|
||||
def _set_state(self, state, timestamp):
|
||||
"""Set sensor state."""
|
||||
if (
|
||||
state < self._attr_state
|
||||
state < self._attr_native_value
|
||||
and self.entity_description.reset_type == ResetType.DAILY
|
||||
):
|
||||
self._attr_last_reset = dt_util.as_utc(
|
||||
timestamp.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
)
|
||||
if (
|
||||
state < self._attr_state
|
||||
state < self._attr_native_value
|
||||
and self.entity_description.reset_type == ResetType.HOURLY
|
||||
):
|
||||
self._attr_last_reset = dt_util.as_utc(
|
||||
timestamp.replace(minute=0, second=0, microsecond=0)
|
||||
)
|
||||
self._attr_state = state
|
||||
self._attr_native_value = state
|
||||
self.async_write_ha_state()
|
||||
|
||||
|
||||
|
@ -65,7 +65,7 @@ class TimeDateSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
|
@ -85,7 +85,7 @@ class TMBSensor(SensorEntity):
|
||||
return ICON
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return self._unit
|
||||
|
||||
@ -95,7 +95,7 @@ class TMBSensor(SensorEntity):
|
||||
return f"{self._stop}_{self._line}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the next departure time."""
|
||||
return self._state
|
||||
|
||||
|
@ -82,12 +82,12 @@ class VL53L1XSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self) -> int:
|
||||
def native_value(self) -> int:
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self) -> str:
|
||||
def native_unit_of_measurement(self) -> str:
|
||||
"""Return the unit of measurement."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
|
@ -130,7 +130,7 @@ class ToonSensor(ToonEntity, SensorEntity):
|
||||
self._attr_last_reset = sensor.get(ATTR_LAST_RESET)
|
||||
self._attr_name = sensor[ATTR_NAME]
|
||||
self._attr_state_class = sensor.get(ATTR_STATE_CLASS)
|
||||
self._attr_unit_of_measurement = sensor[ATTR_UNIT_OF_MEASUREMENT]
|
||||
self._attr_native_unit_of_measurement = sensor[ATTR_UNIT_OF_MEASUREMENT]
|
||||
self._attr_device_class = sensor.get(ATTR_DEVICE_CLASS)
|
||||
self._attr_unique_id = (
|
||||
# This unique ID is a bit ugly and contains unneeded information.
|
||||
@ -139,7 +139,7 @@ class ToonSensor(ToonEntity, SensorEntity):
|
||||
)
|
||||
|
||||
@property
|
||||
def state(self) -> str | None:
|
||||
def native_value(self) -> str | None:
|
||||
"""Return the state of the sensor."""
|
||||
section = getattr(
|
||||
self.coordinator.data, SENSOR_ENTITIES[self.key][ATTR_SECTION]
|
||||
|
@ -120,12 +120,12 @@ class TorqueSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return self._unit
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
|
@ -30,7 +30,7 @@ class TradfriSensor(TradfriBaseDevice, SensorEntity):
|
||||
"""The platform class required by Home Assistant."""
|
||||
|
||||
_attr_device_class = DEVICE_CLASS_BATTERY
|
||||
_attr_unit_of_measurement = PERCENTAGE
|
||||
_attr_native_unit_of_measurement = PERCENTAGE
|
||||
|
||||
def __init__(self, device, api, gateway_id):
|
||||
"""Initialize the device."""
|
||||
@ -38,6 +38,6 @@ class TradfriSensor(TradfriBaseDevice, SensorEntity):
|
||||
self._unique_id = f"{gateway_id}-{device.id}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the current state of the device."""
|
||||
return self._device.device_info.battery_level
|
||||
|
@ -189,7 +189,7 @@ class TrainSensor(SensorEntity):
|
||||
return ICON
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the departure state."""
|
||||
state = self._state
|
||||
if state is not None:
|
||||
|
@ -185,12 +185,12 @@ class TrafikverketWeatherStation(SensorEntity):
|
||||
return self._device_class
|
||||
|
||||
@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
|
||||
|
||||
|
@ -62,7 +62,7 @@ class TransmissionSensor(SensorEntity):
|
||||
return f"{self._tm_client.api.host}-{self.name}"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@ -95,7 +95,7 @@ class TransmissionSpeedSensor(TransmissionSensor):
|
||||
"""Representation of a Transmission speed sensor."""
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement of this entity, if any."""
|
||||
return DATA_RATE_MEGABYTES_PER_SECOND
|
||||
|
||||
@ -145,7 +145,7 @@ class TransmissionTorrentsSensor(TransmissionSensor):
|
||||
}
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit of measurement of this entity, if any."""
|
||||
return "Torrents"
|
||||
|
||||
|
@ -81,7 +81,7 @@ class TransportNSWSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@ -101,7 +101,7 @@ class TransportNSWSensor(SensorEntity):
|
||||
}
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
def native_unit_of_measurement(self):
|
||||
"""Return the unit this state is expressed in."""
|
||||
return TIME_MINUTES
|
||||
|
||||
|
@ -113,12 +113,12 @@ class TravisCISensor(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]
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
|
@ -132,7 +132,7 @@ class TwenteMilieuSensor(SensorEntity):
|
||||
self.async_schedule_update_ha_state(True)
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
|
@ -77,7 +77,7 @@ class TwitchSensor(SensorEntity):
|
||||
return self._channel.display_name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
|
@ -93,7 +93,7 @@ class UkTransportSensor(SensorEntity):
|
||||
|
||||
TRANSPORT_API_URL_BASE = "https://transportapi.com/v3/uk/"
|
||||
_attr_icon = "mdi:train"
|
||||
_attr_unit_of_measurement = TIME_MINUTES
|
||||
_attr_native_unit_of_measurement = TIME_MINUTES
|
||||
|
||||
def __init__(self, name, api_app_id, api_app_key, url):
|
||||
"""Initialize the sensor."""
|
||||
@ -110,7 +110,7 @@ class UkTransportSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
|
@ -86,7 +86,7 @@ class UniFiBandwidthSensor(UniFiClient, SensorEntity):
|
||||
|
||||
DOMAIN = DOMAIN
|
||||
|
||||
_attr_unit_of_measurement = DATA_MEGABYTES
|
||||
_attr_native_unit_of_measurement = DATA_MEGABYTES
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
@ -105,7 +105,7 @@ class UniFiRxBandwidthSensor(UniFiBandwidthSensor):
|
||||
TYPE = RX_SENSOR
|
||||
|
||||
@property
|
||||
def state(self) -> int:
|
||||
def native_value(self) -> int:
|
||||
"""Return the state of the sensor."""
|
||||
if self._is_wired:
|
||||
return self.client.wired_rx_bytes / 1000000
|
||||
@ -118,7 +118,7 @@ class UniFiTxBandwidthSensor(UniFiBandwidthSensor):
|
||||
TYPE = TX_SENSOR
|
||||
|
||||
@property
|
||||
def state(self) -> int:
|
||||
def native_value(self) -> int:
|
||||
"""Return the state of the sensor."""
|
||||
if self._is_wired:
|
||||
return self.client.wired_tx_bytes / 1000000
|
||||
@ -167,7 +167,7 @@ class UniFiUpTimeSensor(UniFiClient, SensorEntity):
|
||||
return f"{super().name} {self.TYPE.capitalize()}"
|
||||
|
||||
@property
|
||||
def state(self) -> datetime:
|
||||
def native_value(self) -> datetime:
|
||||
"""Return the uptime of the client."""
|
||||
if self.client.uptime < 1000000000:
|
||||
return (dt_util.now() - timedelta(seconds=self.client.uptime)).isoformat()
|
||||
|
@ -161,7 +161,7 @@ class UpnpSensor(CoordinatorEntity, SensorEntity):
|
||||
return f"{self._device.udn}_{self._sensor_type['unique_id']}"
|
||||
|
||||
@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 self._sensor_type["unit"]
|
||||
|
||||
@ -180,7 +180,7 @@ class RawUpnpSensor(UpnpSensor):
|
||||
"""Representation of a UPnP/IGD sensor."""
|
||||
|
||||
@property
|
||||
def state(self) -> str | None:
|
||||
def native_value(self) -> str | None:
|
||||
"""Return the state of the device."""
|
||||
device_value_key = self._sensor_type["device_value_key"]
|
||||
value = self.coordinator.data[device_value_key]
|
||||
@ -209,7 +209,7 @@ class DerivedUpnpSensor(UpnpSensor):
|
||||
return f"{self._device.udn}_{self._sensor_type['derived_unique_id']}"
|
||||
|
||||
@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 self._sensor_type["derived_unit"]
|
||||
|
||||
@ -218,7 +218,7 @@ class DerivedUpnpSensor(UpnpSensor):
|
||||
return current_value < self._last_value
|
||||
|
||||
@property
|
||||
def state(self) -> str | None:
|
||||
def native_value(self) -> str | None:
|
||||
"""Return the state of the device."""
|
||||
# Can't calculate any derivative if we have only one value.
|
||||
device_value_key = self._sensor_type["device_value_key"]
|
||||
|
@ -50,4 +50,4 @@ class UptimeSensor(SensorEntity):
|
||||
self._attr_name: str = name
|
||||
self._attr_device_class: str = DEVICE_CLASS_TIMESTAMP
|
||||
self._attr_should_poll: bool = False
|
||||
self._attr_state: str = dt_util.now().isoformat()
|
||||
self._attr_native_value: str = dt_util.now().isoformat()
|
||||
|
@ -54,7 +54,7 @@ class UscisSensor(SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state."""
|
||||
return self._state
|
||||
|
||||
|
@ -321,7 +321,7 @@ class UtilityMeterSensor(RestoreEntity, SensorEntity):
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
def native_value(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@ -336,7 +336,7 @@ class UtilityMeterSensor(RestoreEntity, SensorEntity):
|
||||
return STATE_CLASS_MEASUREMENT
|
||||
|
||||
@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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user