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