Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/acmeda/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AcmedaBattery(AcmedaBase, SensorEntity):
"""Representation of a Acmeda cover device."""

device_class = DEVICE_CLASS_BATTERY
unit_of_measurement = PERCENTAGE
_attr_native_unit_of_measurement = PERCENTAGE

@property
def name(self):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/advantage_air/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,6 @@ def __init__(self, instance, ac_key, zone_key):
)

@property
def state(self):
def native_value(self):
"""Return the current value of the measured temperature."""
return self._zone["measuredTemp"]
2 changes: 1 addition & 1 deletion homeassistant/components/canary/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def __init__(
"model": device.device_type["name"],
"manufacturer": MANUFACTURER,
}
self._attr_unit_of_measurement = sensor_type[1]
self._attr_native_unit_of_measurement = sensor_type[1]
self._attr_device_class = sensor_type[3]
self._attr_icon = sensor_type[2]

Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/ezviz/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

from pyezviz.constants import SensorType

from homeassistant.components.sensor import SensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo, Entity
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity

Expand Down Expand Up @@ -39,7 +40,7 @@ async def async_setup_entry(
async_add_entities(sensors)


class EzvizSensor(CoordinatorEntity, Entity):
class EzvizSensor(CoordinatorEntity, SensorEntity):
"""Representation of a Ezviz sensor."""

coordinator: EzvizDataUpdateCoordinator
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/flipr/sensor.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""Sensor platform for the Flipr's pool_sensor."""
from datetime import datetime

from homeassistant.components.sensor import SensorEntity
from homeassistant.const import (
ATTR_ATTRIBUTION,
DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_TIMESTAMP,
TEMP_CELSIUS,
)
from homeassistant.helpers.entity import Entity

from . import FliprEntity
from .const import ATTRIBUTION, CONF_FLIPR_ID, DOMAIN
Expand Down Expand Up @@ -53,7 +53,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
async_add_entities(sensors_list, True)


class FliprSensor(FliprEntity, Entity):
class FliprSensor(FliprEntity, SensorEntity):
"""Sensor representing FliprSensor data."""

@property
Expand All @@ -62,7 +62,7 @@ def name(self):
return f"Flipr {self.flipr_id} {SENSORS[self.info_type]['name']}"

@property
def state(self):
def native_value(self):
"""State of the sensor."""
state = self.coordinator.data[self.info_type]
if isinstance(state, datetime):
Expand All @@ -80,7 +80,7 @@ def icon(self):
return SENSORS[self.info_type]["icon"]

@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return unit of measurement."""
return SENSORS[self.info_type]["unit"]

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/fritzbox/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class FritzBoxPowerSensor(FritzBoxSensor):
"""The entity class for FRITZ!SmartHome power consumption sensors."""

@property
def state(self) -> float | None:
def native_value(self) -> float | None:
"""Return the state of the sensor."""
if power := self.device.power:
return power / 1000 # type: ignore [no-any-return]
Expand All @@ -147,7 +147,7 @@ class FritzBoxEnergySensor(FritzBoxSensor):
"""The entity class for FRITZ!SmartHome total energy sensors."""

@property
def state(self) -> float | None:
def native_value(self) -> float | None:
"""Return the state of the sensor."""
if energy := self.device.energy:
return energy / 1000 # type: ignore [no-any-return]
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/fronius/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,9 @@ def available(self):
async def async_update(self):
"""Update the internal state."""
state = self._parent.data.get(self._key)
self._attr_state = state.get("value")
if isinstance(self._attr_state, float):
self._attr_native_value = round(self._attr_state, 2)
self._attr_native_value = state.get("value")
if isinstance(self._attr_native_value, float):
self._attr_native_value = round(self._attr_native_value, 2)
self._attr_native_unit_of_measurement = state.get("unit")

@property
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/mill/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, heater, mill_data_connection, sensor_type):
self._attr_device_class = DEVICE_CLASS_ENERGY
self._attr_name = f"{heater.name} {sensor_type.replace('_', ' ')}"
self._attr_unique_id = f"{heater.device_id}_{sensor_type}"
self._attr_unit_of_measurement = ENERGY_KILO_WATT_HOUR
self._attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR
self._attr_state_class = STATE_CLASS_MEASUREMENT
self._attr_device_info = {
"identifiers": {(DOMAIN, heater.device_id)},
Expand Down Expand Up @@ -67,7 +67,7 @@ async def async_update(self):
else:
_state = None
if _state is None:
self._attr_state = _state
self._attr_native_value = _state
return

if self.state is not None and _state < self.state:
Expand All @@ -81,4 +81,4 @@ async def async_update(self):
month=1, day=1, hour=0, minute=0, second=0, microsecond=0
)
)
self._attr_state = _state
self._attr_native_value = _state
4 changes: 2 additions & 2 deletions homeassistant/components/powerwall/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class PowerWallEnergyDirectionSensor(PowerWallEntity, SensorEntity):
"""Representation of an Powerwall Direction Energy sensor."""

_attr_state_class = STATE_CLASS_MEASUREMENT
_attr_unit_of_measurement = ENERGY_KILO_WATT_HOUR
_attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR
_attr_device_class = DEVICE_CLASS_ENERGY
_attr_last_reset = dt_util.utc_from_timestamp(0)

Expand Down Expand Up @@ -180,7 +180,7 @@ def __init__(
)

@property
def state(self):
def native_value(self):
"""Get the current value in kWh."""
meter = self.coordinator.data[POWERWALL_API_METERS].get_meter(self._meter)
if self._meter_direction == _METER_DIRECTION_EXPORT:
Expand Down
9 changes: 5 additions & 4 deletions homeassistant/components/pvpc_hourly_pricing/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from aiopvpc import PVPCData

from homeassistant.components.sensor import SensorEntity
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_NAME, CURRENCY_EURO, ENERGY_KILO_WATT_HOUR
from homeassistant.core import HomeAssistant, callback
Expand Down Expand Up @@ -51,9 +51,10 @@ async def async_setup_entry(
class ElecPriceSensor(RestoreEntity, SensorEntity):
"""Class to hold the prices of electricity as a sensor."""

unit_of_measurement = UNIT
icon = ICON
should_poll = False
_attr_icon = ICON
_attr_native_unit_of_measurement = UNIT
_attr_should_poll = False
_attr_state_class = STATE_CLASS_MEASUREMENT

def __init__(self, name, unique_id, pvpc_data_handler):
"""Initialize the sensor object."""
Expand Down
42 changes: 21 additions & 21 deletions homeassistant/components/renault/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ class RenaultBatteryAutonomySensor(RenaultBatteryDataEntity, SensorEntity):
"""Battery autonomy sensor."""

_attr_icon = "mdi:ev-station"
_attr_unit_of_measurement = LENGTH_KILOMETERS
_attr_native_unit_of_measurement = LENGTH_KILOMETERS

@property
def state(self) -> int | None:
def native_value(self) -> int | None:
"""Return the state of this entity."""
return self.data.batteryAutonomy if self.data else None

Expand All @@ -100,10 +100,10 @@ class RenaultBatteryLevelSensor(RenaultBatteryDataEntity, SensorEntity):
"""Battery Level sensor."""

_attr_device_class = DEVICE_CLASS_BATTERY
_attr_unit_of_measurement = PERCENTAGE
_attr_native_unit_of_measurement = PERCENTAGE

@property
def state(self) -> int | None:
def native_value(self) -> int | None:
"""Return the state of this entity."""
return self.data.batteryLevel if self.data else None

Expand All @@ -128,10 +128,10 @@ class RenaultBatteryTemperatureSensor(RenaultBatteryDataEntity, SensorEntity):
"""Battery Temperature sensor."""

_attr_device_class = DEVICE_CLASS_TEMPERATURE
_attr_unit_of_measurement = TEMP_CELSIUS
_attr_native_unit_of_measurement = TEMP_CELSIUS

@property
def state(self) -> int | None:
def native_value(self) -> int | None:
"""Return the state of this entity."""
return self.data.batteryTemperature if self.data else None

Expand All @@ -142,7 +142,7 @@ class RenaultChargeModeSensor(RenaultChargeModeDataEntity, SensorEntity):
_attr_device_class = DEVICE_CLASS_CHARGE_MODE

@property
def state(self) -> str | None:
def native_value(self) -> str | None:
"""Return the state of this entity."""
return self.data.chargeMode if self.data else None

Expand All @@ -160,7 +160,7 @@ class RenaultChargeStateSensor(RenaultBatteryDataEntity, SensorEntity):
_attr_device_class = DEVICE_CLASS_CHARGE_STATE

@property
def state(self) -> str | None:
def native_value(self) -> str | None:
"""Return the state of this entity."""
charging_status = self.data.get_charging_status() if self.data else None
return slugify(charging_status.name) if charging_status is not None else None
Expand All @@ -175,10 +175,10 @@ class RenaultChargingRemainingTimeSensor(RenaultBatteryDataEntity, SensorEntity)
"""Charging Remaining Time sensor."""

_attr_icon = "mdi:timer"
_attr_unit_of_measurement = TIME_MINUTES
_attr_native_unit_of_measurement = TIME_MINUTES

@property
def state(self) -> int | None:
def native_value(self) -> int | None:
"""Return the state of this entity."""
return self.data.chargingRemainingTime if self.data else None

Expand All @@ -187,10 +187,10 @@ class RenaultChargingPowerSensor(RenaultBatteryDataEntity, SensorEntity):
"""Charging Power sensor."""

_attr_device_class = DEVICE_CLASS_ENERGY
_attr_unit_of_measurement = POWER_KILO_WATT
_attr_native_unit_of_measurement = POWER_KILO_WATT

@property
def state(self) -> float | None:
def native_value(self) -> float | None:
"""Return the state of this entity."""
if not self.data or self.data.chargingInstantaneousPower is None:
return None
Expand All @@ -204,10 +204,10 @@ class RenaultFuelAutonomySensor(RenaultCockpitDataEntity, SensorEntity):
"""Fuel autonomy sensor."""

_attr_icon = "mdi:gas-station"
_attr_unit_of_measurement = LENGTH_KILOMETERS
_attr_native_unit_of_measurement = LENGTH_KILOMETERS

@property
def state(self) -> int | None:
def native_value(self) -> int | None:
"""Return the state of this entity."""
return (
round(self.data.fuelAutonomy)
Expand All @@ -220,10 +220,10 @@ class RenaultFuelQuantitySensor(RenaultCockpitDataEntity, SensorEntity):
"""Fuel quantity sensor."""

_attr_icon = "mdi:fuel"
_attr_unit_of_measurement = VOLUME_LITERS
_attr_native_unit_of_measurement = VOLUME_LITERS

@property
def state(self) -> int | None:
def native_value(self) -> int | None:
"""Return the state of this entity."""
return (
round(self.data.fuelQuantity)
Expand All @@ -236,10 +236,10 @@ class RenaultMileageSensor(RenaultCockpitDataEntity, SensorEntity):
"""Mileage sensor."""

_attr_icon = "mdi:sign-direction"
_attr_unit_of_measurement = LENGTH_KILOMETERS
_attr_native_unit_of_measurement = LENGTH_KILOMETERS

@property
def state(self) -> int | None:
def native_value(self) -> int | None:
"""Return the state of this entity."""
return (
round(self.data.totalMileage)
Expand All @@ -252,10 +252,10 @@ class RenaultOutsideTemperatureSensor(RenaultHVACDataEntity, SensorEntity):
"""HVAC Outside Temperature sensor."""

_attr_device_class = DEVICE_CLASS_TEMPERATURE
_attr_unit_of_measurement = TEMP_CELSIUS
_attr_native_unit_of_measurement = TEMP_CELSIUS

@property
def state(self) -> float | None:
def native_value(self) -> float | None:
"""Return the state of this entity."""
return self.data.externalTemperature if self.data else None

Expand All @@ -266,7 +266,7 @@ class RenaultPlugStateSensor(RenaultBatteryDataEntity, SensorEntity):
_attr_device_class = DEVICE_CLASS_PLUG_STATE

@property
def state(self) -> str | None:
def native_value(self) -> str | None:
"""Return the state of this entity."""
plug_status = self.data.get_plug_status() if self.data else None
return slugify(plug_status.name) if plug_status is not None else None
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/smartthings/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ def unique_id(self) -> str:
return f"{self._device.device_id}.{self.report_name}"

@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
value = self._device.status.attributes[Attribute.power_consumption].value
if value is None or value.get(self.report_name) is None:
Expand All @@ -585,7 +585,7 @@ def device_class(self):
return DEVICE_CLASS_ENERGY

@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit this state is expressed in."""
if self.report_name == "power":
return POWER_WATT
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/spider/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async def async_setup_entry(hass, config, async_add_entities):
class SpiderPowerPlugEnergy(SensorEntity):
"""Representation of a Spider Power Plug (energy)."""

_attr_unit_of_measurement = ENERGY_KILO_WATT_HOUR
_attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR
_attr_device_class = DEVICE_CLASS_ENERGY
_attr_state_class = STATE_CLASS_MEASUREMENT

Expand Down Expand Up @@ -59,7 +59,7 @@ def name(self) -> str:
return f"{self.power_plug.name} Total Energy Today"

@property
def state(self) -> float:
def native_value(self) -> float:
"""Return todays energy usage in Kwh."""
return round(self.power_plug.today_energy_consumption / 1000, 2)

Expand All @@ -80,7 +80,7 @@ class SpiderPowerPlugPower(SensorEntity):

_attr_device_class = DEVICE_CLASS_POWER
_attr_state_class = STATE_CLASS_MEASUREMENT
_attr_unit_of_measurement = POWER_WATT
_attr_native_unit_of_measurement = POWER_WATT

def __init__(self, api, power_plug) -> None:
"""Initialize the Spider Power Plug."""
Expand Down Expand Up @@ -108,7 +108,7 @@ def name(self) -> str:
return f"{self.power_plug.name} Power Consumption"

@property
def state(self) -> float:
def native_value(self) -> float:
"""Return the current power usage in W."""
return round(self.power_plug.current_energy_consumption)

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/tplink/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def data(self) -> dict[str, Any]:
return self.coordinator.data

@property
def state(self) -> float | None:
def native_value(self) -> float | None:
"""Return the sensors state."""
return self.data[CONF_EMETER_PARAMS][self.entity_description.key]

Expand Down
Loading