Move temperature conversions to sensor base class (3/8) (#54469)

* Move temperature conversions to entity base class (3/8)

* Fix FritzBox sensor

* Fix tests
This commit is contained in:
Erik Montnemery 2021-08-12 14:23:56 +02:00 committed by GitHub
parent 103e21c278
commit 6de6a5dc14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
70 changed files with 350 additions and 324 deletions

View File

@ -70,7 +70,7 @@ class BanSensor(SensorEntity):
return self.ban_dict
@property
def state(self):
def native_value(self):
"""Return the most recently banned IP Address."""
return self.last_ban

View File

@ -30,10 +30,10 @@ class SpeedtestSensor(RestoreEntity, SensorEntity):
"""Implementation of a FAst.com sensor."""
_attr_name = "Fast.com Download"
_attr_unit_of_measurement = DATA_RATE_MEGABITS_PER_SECOND
_attr_native_unit_of_measurement = DATA_RATE_MEGABITS_PER_SECOND
_attr_icon = ICON
_attr_should_poll = False
_attr_state = None
_attr_native_value = None
def __init__(self, speedtest_data: dict[str, Any]) -> None:
"""Initialize the sensor."""
@ -52,14 +52,14 @@ class SpeedtestSensor(RestoreEntity, SensorEntity):
state = await self.async_get_last_state()
if not state:
return
self._attr_state = state.state
self._attr_native_value = state.state
def update(self) -> None:
"""Get the latest data and update the states."""
data = self._speedtest_data.data # type: ignore[attr-defined]
if data is None:
return
self._attr_state = data["download"]
self._attr_native_value = data["download"]
@callback
def _schedule_immediate_update(self) -> None:

View File

@ -85,12 +85,12 @@ class FibaroSensor(FibaroDevice, SensorEntity):
self._unit = self.fibaro_device.properties.unit
@property
def state(self):
def native_value(self):
"""Return the state 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."""
return self._unit

View File

@ -109,12 +109,12 @@ class FidoSensor(SensorEntity):
return f"{self.client_name} {self._number} {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

View File

@ -62,7 +62,7 @@ class FileSensor(SensorEntity):
return self._name
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self._unit_of_measurement
@ -72,7 +72,7 @@ class FileSensor(SensorEntity):
return ICON
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._state

View File

@ -63,7 +63,7 @@ class Filesize(SensorEntity):
return self._name
@property
def state(self):
def native_value(self):
"""Return the size of the file in MB."""
decimals = 2
state_mb = round(self._size / 1e6, decimals)
@ -84,6 +84,6 @@ class Filesize(SensorEntity):
}
@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

View File

@ -332,7 +332,7 @@ class SensorFilter(SensorEntity):
return self._name
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._state
@ -342,7 +342,7 @@ class SensorFilter(SensorEntity):
return self._icon
@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

View File

@ -179,8 +179,8 @@ class FinTsAccount(SensorEntity):
"""Get the current balance and currency for the account."""
bank = self._client.client
balance = bank.get_balance(self._account)
self._attr_state = balance.amount.amount
self._attr_unit_of_measurement = balance.amount.currency
self._attr_native_value = balance.amount.amount
self._attr_native_unit_of_measurement = balance.amount.currency
_LOGGER.debug("updated balance of account %s", self.name)
@ -198,13 +198,13 @@ class FinTsHoldingsAccount(SensorEntity):
self._account = account
self._holdings: list[Any] = []
self._attr_icon = ICON
self._attr_unit_of_measurement = "EUR"
self._attr_native_unit_of_measurement = "EUR"
def update(self) -> None:
"""Get the current holdings for the account."""
bank = self._client.client
self._holdings = bank.get_holdings(self._account)
self._attr_state = sum(h.total_value for h in self._holdings)
self._attr_native_value = sum(h.total_value for h in self._holdings)
@property
def extra_state_attributes(self) -> dict:

View File

@ -49,7 +49,7 @@ class IncidentsSensor(RestoreEntity, SensorEntity):
return "mdi:fire-truck"
@property
def state(self) -> str:
def native_value(self) -> str:
"""Return the state of the sensor."""
return self._state

View File

@ -54,6 +54,6 @@ class FirmataSensor(FirmataPinEntity, SensorEntity):
await self._api.stop_pin()
@property
def state(self) -> int:
def native_value(self) -> int:
"""Return sensor state."""
return self._api.state

View File

@ -374,12 +374,12 @@ class FitbitSensor(SensorEntity):
return self._name
@property
def state(self) -> str | None:
def native_value(self) -> str | None:
"""Return the state of the sensor."""
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, if any."""
return self._unit_of_measurement

View File

@ -64,12 +64,12 @@ class ExchangeRateSensor(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 self._target
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._state

View File

@ -36,7 +36,7 @@ async def async_setup_entry(
class FlickPricingSensor(SensorEntity):
"""Entity object for Flick Electric sensor."""
_attr_unit_of_measurement = UNIT_NAME
_attr_native_unit_of_measurement = UNIT_NAME
def __init__(self, api: FlickAPI) -> None:
"""Entity object for Flick Electric sensor."""
@ -53,7 +53,7 @@ class FlickPricingSensor(SensorEntity):
return FRIENDLY_NAME
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._price.price

View File

@ -61,7 +61,7 @@ class FloDailyUsageSensor(FloEntity, SensorEntity):
"""Monitors the daily water usage."""
_attr_icon = WATER_ICON
_attr_unit_of_measurement = VOLUME_GALLONS
_attr_native_unit_of_measurement = VOLUME_GALLONS
def __init__(self, device):
"""Initialize the daily water usage sensor."""
@ -69,7 +69,7 @@ class FloDailyUsageSensor(FloEntity, SensorEntity):
self._state: float = None
@property
def state(self) -> float | None:
def native_value(self) -> float | None:
"""Return the current daily usage."""
if self._device.consumption_today is None:
return None
@ -85,7 +85,7 @@ class FloSystemModeSensor(FloEntity, SensorEntity):
self._state: str = None
@property
def state(self) -> str | None:
def native_value(self) -> str | None:
"""Return the current system mode."""
if not self._device.current_system_mode:
return None
@ -96,7 +96,7 @@ class FloCurrentFlowRateSensor(FloEntity, SensorEntity):
"""Monitors the current water flow rate."""
_attr_icon = GAUGE_ICON
_attr_unit_of_measurement = "gpm"
_attr_native_unit_of_measurement = "gpm"
def __init__(self, device):
"""Initialize the flow rate sensor."""
@ -104,7 +104,7 @@ class FloCurrentFlowRateSensor(FloEntity, SensorEntity):
self._state: float = None
@property
def state(self) -> float | None:
def native_value(self) -> float | None:
"""Return the current flow rate."""
if self._device.current_flow_rate is None:
return None
@ -115,7 +115,7 @@ class FloTemperatureSensor(FloEntity, SensorEntity):
"""Monitors the temperature."""
_attr_device_class = DEVICE_CLASS_TEMPERATURE
_attr_unit_of_measurement = TEMP_FAHRENHEIT
_attr_native_unit_of_measurement = TEMP_FAHRENHEIT
def __init__(self, name, device):
"""Initialize the temperature sensor."""
@ -123,7 +123,7 @@ class FloTemperatureSensor(FloEntity, SensorEntity):
self._state: float = None
@property
def state(self) -> float | None:
def native_value(self) -> float | None:
"""Return the current temperature."""
if self._device.temperature is None:
return None
@ -134,7 +134,7 @@ class FloHumiditySensor(FloEntity, SensorEntity):
"""Monitors the humidity."""
_attr_device_class = DEVICE_CLASS_HUMIDITY
_attr_unit_of_measurement = PERCENTAGE
_attr_native_unit_of_measurement = PERCENTAGE
def __init__(self, device):
"""Initialize the humidity sensor."""
@ -142,7 +142,7 @@ class FloHumiditySensor(FloEntity, SensorEntity):
self._state: float = None
@property
def state(self) -> float | None:
def native_value(self) -> float | None:
"""Return the current humidity."""
if self._device.humidity is None:
return None
@ -153,7 +153,7 @@ class FloPressureSensor(FloEntity, SensorEntity):
"""Monitors the water pressure."""
_attr_device_class = DEVICE_CLASS_PRESSURE
_attr_unit_of_measurement = PRESSURE_PSI
_attr_native_unit_of_measurement = PRESSURE_PSI
def __init__(self, device):
"""Initialize the pressure sensor."""
@ -161,7 +161,7 @@ class FloPressureSensor(FloEntity, SensorEntity):
self._state: float = None
@property
def state(self) -> float | None:
def native_value(self) -> float | None:
"""Return the current water pressure."""
if self._device.current_psi is None:
return None
@ -172,7 +172,7 @@ class FloBatterySensor(FloEntity, SensorEntity):
"""Monitors the battery level for battery-powered leak detectors."""
_attr_device_class = DEVICE_CLASS_BATTERY
_attr_unit_of_measurement = PERCENTAGE
_attr_native_unit_of_measurement = PERCENTAGE
def __init__(self, device):
"""Initialize the battery sensor."""
@ -180,6 +180,6 @@ class FloBatterySensor(FloEntity, SensorEntity):
self._state: float = None
@property
def state(self) -> float | None:
def native_value(self) -> float | None:
"""Return the current battery level."""
return self._device.battery_level

View File

@ -136,7 +136,7 @@ class FlumeSensor(CoordinatorEntity, SensorEntity):
return self._name
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
sensor_key = self._flume_query_sensor[0]
if sensor_key not in self._flume_device.values:
@ -145,7 +145,7 @@ class FlumeSensor(CoordinatorEntity, SensorEntity):
return _format_state_value(self._flume_device.values[sensor_key])
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit the value is expressed in."""
# This is in gallons per SCAN_INTERVAL
return self._flume_query_sensor[1]["unit_of_measurement"]

View File

@ -116,7 +116,7 @@ class FluNearYouSensor(CoordinatorEntity, SensorEntity):
f"{entry.data[CONF_LATITUDE]},"
f"{entry.data[CONF_LONGITUDE]}_{sensor_type}"
)
self._attr_unit_of_measurement = unit
self._attr_native_unit_of_measurement = unit
self._entry = entry
self._sensor_type = sensor_type
@ -149,7 +149,7 @@ class CdcSensor(FluNearYouSensor):
ATTR_STATE: self.coordinator.data["name"],
}
)
self._attr_state = self.coordinator.data[self._sensor_type]
self._attr_native_value = self.coordinator.data[self._sensor_type]
class UserSensor(FluNearYouSensor):
@ -181,7 +181,7 @@ class UserSensor(FluNearYouSensor):
] = self.coordinator.data["state"]["last_week_data"][states_key]
if self._sensor_type == SENSOR_TYPE_USER_TOTAL:
self._attr_state = sum(
self._attr_native_value = sum(
v
for k, v in self.coordinator.data["local"].items()
if k
@ -194,4 +194,4 @@ class UserSensor(FluNearYouSensor):
)
)
else:
self._attr_state = self.coordinator.data["local"][self._sensor_type]
self._attr_native_value = self.coordinator.data["local"][self._sensor_type]

View File

@ -79,7 +79,7 @@ class Folder(SensorEntity):
return self._name
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
decimals = 2
size_mb = round(self._size / 1e6, decimals)
@ -102,6 +102,6 @@ class Folder(SensorEntity):
}
@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

View File

@ -126,7 +126,7 @@ class FoobotSensor(SensorEntity):
return SENSOR_TYPES[self.type][2]
@property
def state(self):
def native_value(self):
"""Return the state of the device."""
try:
data = self.foobot_data.data[self.type]
@ -140,7 +140,7 @@ class FoobotSensor(SensorEntity):
return f"{self._uuid}_{self.type}"
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement of this entity."""
return self._unit_of_measurement

View File

@ -30,14 +30,14 @@ SENSORS: tuple[ForecastSolarSensorEntityDescription, ...] = (
name="Estimated Energy Production - Today",
state=lambda estimate: estimate.energy_production_today / 1000,
device_class=DEVICE_CLASS_ENERGY,
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
),
ForecastSolarSensorEntityDescription(
key="energy_production_tomorrow",
name="Estimated Energy Production - Tomorrow",
state=lambda estimate: estimate.energy_production_tomorrow / 1000,
device_class=DEVICE_CLASS_ENERGY,
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
),
ForecastSolarSensorEntityDescription(
key="power_highest_peak_time_today",
@ -55,7 +55,7 @@ SENSORS: tuple[ForecastSolarSensorEntityDescription, ...] = (
device_class=DEVICE_CLASS_POWER,
state=lambda estimate: estimate.power_production_now,
state_class=STATE_CLASS_MEASUREMENT,
unit_of_measurement=POWER_WATT,
native_unit_of_measurement=POWER_WATT,
),
ForecastSolarSensorEntityDescription(
key="power_production_next_hour",
@ -65,7 +65,7 @@ SENSORS: tuple[ForecastSolarSensorEntityDescription, ...] = (
name="Estimated Power Production - Next Hour",
device_class=DEVICE_CLASS_POWER,
entity_registry_enabled_default=False,
unit_of_measurement=POWER_WATT,
native_unit_of_measurement=POWER_WATT,
),
ForecastSolarSensorEntityDescription(
key="power_production_next_12hours",
@ -75,7 +75,7 @@ SENSORS: tuple[ForecastSolarSensorEntityDescription, ...] = (
name="Estimated Power Production - Next 12 Hours",
device_class=DEVICE_CLASS_POWER,
entity_registry_enabled_default=False,
unit_of_measurement=POWER_WATT,
native_unit_of_measurement=POWER_WATT,
),
ForecastSolarSensorEntityDescription(
key="power_production_next_24hours",
@ -85,20 +85,20 @@ SENSORS: tuple[ForecastSolarSensorEntityDescription, ...] = (
name="Estimated Power Production - Next 24 Hours",
device_class=DEVICE_CLASS_POWER,
entity_registry_enabled_default=False,
unit_of_measurement=POWER_WATT,
native_unit_of_measurement=POWER_WATT,
),
ForecastSolarSensorEntityDescription(
key="energy_current_hour",
name="Estimated Energy Production - This Hour",
state=lambda estimate: estimate.energy_current_hour / 1000,
device_class=DEVICE_CLASS_ENERGY,
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
),
ForecastSolarSensorEntityDescription(
key="energy_next_hour",
state=lambda estimate: estimate.sum_energy_production(1) / 1000,
name="Estimated Energy Production - Next Hour",
device_class=DEVICE_CLASS_ENERGY,
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
),
)

View File

@ -60,7 +60,7 @@ class ForecastSolarSensorEntity(CoordinatorEntity, SensorEntity):
}
@property
def state(self) -> StateType:
def native_value(self) -> StateType:
"""Return the state of the sensor."""
if self.entity_description.state is None:
state: StateType | datetime = getattr(

View File

@ -109,12 +109,12 @@ class FreeboxSensor(SensorEntity):
return self._name
@property
def state(self) -> str:
def native_value(self) -> str:
"""Return the state."""
return self._state
@property
def unit_of_measurement(self) -> str:
def native_unit_of_measurement(self) -> str:
"""Return the unit."""
return self._unit

View File

@ -64,8 +64,8 @@ class Device(CoordinatorEntity, SensorEntity):
}
self._attr_device_class = DEVICE_CLASS_MAP[device["type"]]
self._attr_state_class = STATE_CLASS_MAP[device["type"]]
self._attr_unit_of_measurement = UNIT_MAP[device["type"]]
self._attr_state = 0
self._attr_native_unit_of_measurement = UNIT_MAP[device["type"]]
self._attr_native_value = 0
@callback
def _handle_coordinator_update(self) -> None:
@ -80,7 +80,7 @@ class Device(CoordinatorEntity, SensorEntity):
)
if device is not None and "state" in device:
state = device["state"]
self._attr_state = state[DEVICE_KEY_MAP[self._type]]
self._attr_native_value = state[DEVICE_KEY_MAP[self._type]]
super()._handle_coordinator_update()
async def async_added_to_hass(self) -> None:

View File

@ -290,7 +290,9 @@ class FritzBoxSensor(FritzBoxBaseEntity, SensorEntity):
self._attr_icon = self._sensor_data.get("icon")
self._attr_name = f"{device_friendly_name} {self._sensor_data['name']}"
self._attr_state_class = self._sensor_data.get("state_class")
self._attr_unit_of_measurement = self._sensor_data.get("unit_of_measurement")
self._attr_native_unit_of_measurement = self._sensor_data.get(
"unit_of_measurement"
)
self._attr_unique_id = f"{fritzbox_tools.unique_id}-{sensor_type}"
super().__init__(fritzbox_tools, device_friendly_name)
@ -311,7 +313,7 @@ class FritzBoxSensor(FritzBoxBaseEntity, SensorEntity):
self._attr_available = False
return
self._attr_state = self._last_device_value = self._state_provider(
self._attr_native_value = self._last_device_value = self._state_provider(
status, self._last_device_value
)

View File

@ -12,7 +12,6 @@ from homeassistant.const import (
ATTR_DEVICE_CLASS,
ATTR_ENTITY_ID,
ATTR_NAME,
ATTR_UNIT_OF_MEASUREMENT,
CONF_HOST,
CONF_PASSWORD,
CONF_USERNAME,
@ -139,7 +138,6 @@ class FritzBoxEntity(CoordinatorEntity):
self.ain = ain
self._name = entity_info[ATTR_NAME]
self._unique_id = entity_info[ATTR_ENTITY_ID]
self._unit_of_measurement = entity_info[ATTR_UNIT_OF_MEASUREMENT]
self._device_class = entity_info[ATTR_DEVICE_CLASS]
self._attr_state_class = entity_info[ATTR_STATE_CLASS]
@ -174,11 +172,6 @@ class FritzBoxEntity(CoordinatorEntity):
"""Return the name of the device."""
return self._name
@property
def unit_of_measurement(self) -> str | None:
"""Return the unit of measurement."""
return self._unit_of_measurement
@property
def device_class(self) -> str | None:
"""Return the device class."""

View File

@ -3,6 +3,8 @@ from __future__ import annotations
from datetime import datetime
from pyfritzhome import FritzhomeDevice
from homeassistant.components.sensor import (
ATTR_STATE_CLASS,
STATE_CLASS_MEASUREMENT,
@ -25,6 +27,7 @@ from homeassistant.const import (
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from homeassistant.util.dt import utc_from_timestamp
from . import FritzBoxEntity
@ -34,7 +37,7 @@ from .const import (
CONF_COORDINATOR,
DOMAIN as FRITZBOX_DOMAIN,
)
from .model import SensorExtraAttributes
from .model import EntityInfo, SensorExtraAttributes
async def async_setup_entry(
@ -106,16 +109,30 @@ async def async_setup_entry(
async_add_entities(entities)
class FritzBoxBatterySensor(FritzBoxEntity, SensorEntity):
class FritzBoxSensor(FritzBoxEntity, SensorEntity):
"""The entity class for FRITZ!SmartHome sensors."""
def __init__(
self,
entity_info: EntityInfo,
coordinator: DataUpdateCoordinator[dict[str, FritzhomeDevice]],
ain: str,
) -> None:
"""Initialize the FritzBox entity."""
FritzBoxEntity.__init__(self, entity_info, coordinator, ain)
self._attr_native_unit_of_measurement = entity_info[ATTR_UNIT_OF_MEASUREMENT]
class FritzBoxBatterySensor(FritzBoxSensor):
"""The entity class for FRITZ!SmartHome battery sensors."""
@property
def state(self) -> int | None:
def native_value(self) -> int | None:
"""Return the state of the sensor."""
return self.device.battery_level # type: ignore [no-any-return]
class FritzBoxPowerSensor(FritzBoxEntity, SensorEntity):
class FritzBoxPowerSensor(FritzBoxSensor):
"""The entity class for FRITZ!SmartHome power consumption sensors."""
@property
@ -126,7 +143,7 @@ class FritzBoxPowerSensor(FritzBoxEntity, SensorEntity):
return 0.0
class FritzBoxEnergySensor(FritzBoxEntity, SensorEntity):
class FritzBoxEnergySensor(FritzBoxSensor):
"""The entity class for FRITZ!SmartHome total energy sensors."""
@property
@ -143,11 +160,11 @@ class FritzBoxEnergySensor(FritzBoxEntity, SensorEntity):
return utc_from_timestamp(0)
class FritzBoxTempSensor(FritzBoxEntity, SensorEntity):
class FritzBoxTempSensor(FritzBoxSensor):
"""The entity class for FRITZ!SmartHome temperature sensors."""
@property
def state(self) -> float | None:
def native_value(self) -> float | None:
"""Return the state of the sensor."""
return self.device.temperature # type: ignore [no-any-return]

View File

@ -158,7 +158,7 @@ class FritzBoxCallSensor(SensorEntity):
return self._fritzbox_phonebook is not None
@property
def state(self):
def native_value(self):
"""Return the state of the device."""
return self._state

View File

@ -308,8 +308,8 @@ class FroniusTemplateSensor(SensorEntity):
state = self._parent.data.get(self._key)
self._attr_state = state.get("value")
if isinstance(self._attr_state, float):
self._attr_state = round(self._attr_state, 2)
self._attr_unit_of_measurement = state.get("unit")
self._attr_native_value = round(self._attr_state, 2)
self._attr_native_unit_of_measurement = state.get("unit")
@property
def last_reset(self) -> dt.dt.datetime | None:

View File

@ -76,7 +76,7 @@ class GaragesamsterdamSensor(CoordinatorEntity, SensorEntity):
)
@property
def state(self) -> str:
def native_value(self) -> str:
"""Return the state of the sensor."""
return getattr(self.coordinator.data[self._garage_name], self._info_type)
@ -86,7 +86,7 @@ class GaragesamsterdamSensor(CoordinatorEntity, SensorEntity):
return SENSORS[self._info_type]
@property
def unit_of_measurement(self) -> str:
def native_unit_of_measurement(self) -> str:
"""Return unit of measurement."""
return "cars"

View File

@ -105,7 +105,7 @@ class GdacsSensor(SensorEntity):
self._removed = status_info.removed
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._total
@ -125,7 +125,7 @@ class GdacsSensor(SensorEntity):
return DEFAULT_ICON
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement."""
return DEFAULT_UNIT_OF_MEASUREMENT

View File

@ -79,12 +79,12 @@ class GeniusBattery(GeniusDevice, SensorEntity):
return DEVICE_CLASS_BATTERY
@property
def unit_of_measurement(self) -> str:
def native_unit_of_measurement(self) -> str:
"""Return the unit of measurement of the sensor."""
return PERCENTAGE
@property
def state(self) -> str:
def native_value(self) -> str:
"""Return the state of the sensor."""
level = self._device.data["state"][self._state_attr]
return level if level != 255 else 0
@ -105,7 +105,7 @@ class GeniusIssue(GeniusEntity, SensorEntity):
self._issues = []
@property
def state(self) -> str:
def native_value(self) -> str:
"""Return the number of issues."""
return len(self._issues)

View File

@ -121,12 +121,12 @@ class GeoRssServiceSensor(SensorEntity):
return f"{self._service_name} {'Any' if self._category is None else self._category}"
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._state
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement."""
return self._unit_of_measurement

View File

@ -106,7 +106,7 @@ class GeonetnzQuakesSensor(SensorEntity):
self._removed = status_info.removed
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._total
@ -126,7 +126,7 @@ class GeonetnzQuakesSensor(SensorEntity):
return DEFAULT_ICON
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement."""
return DEFAULT_UNIT_OF_MEASUREMENT

View File

@ -130,7 +130,7 @@ class GeonetnzVolcanoSensor(SensorEntity):
)
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._alert_level
@ -145,7 +145,7 @@ class GeonetnzVolcanoSensor(SensorEntity):
return f"Volcano {self._title}"
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement."""
return "alert level"

View File

@ -41,43 +41,43 @@ SENSOR_TYPES: Final[tuple[GiosSensorEntityDescription, ...]] = (
GiosSensorEntityDescription(
key=ATTR_C6H6,
name="C6H6",
unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
state_class=STATE_CLASS_MEASUREMENT,
),
GiosSensorEntityDescription(
key=ATTR_CO,
name="CO",
unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
state_class=STATE_CLASS_MEASUREMENT,
),
GiosSensorEntityDescription(
key=ATTR_NO2,
name="NO2",
unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
state_class=STATE_CLASS_MEASUREMENT,
),
GiosSensorEntityDescription(
key=ATTR_O3,
name="O3",
unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
state_class=STATE_CLASS_MEASUREMENT,
),
GiosSensorEntityDescription(
key=ATTR_PM10,
name="PM10",
unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
state_class=STATE_CLASS_MEASUREMENT,
),
GiosSensorEntityDescription(
key=ATTR_PM25,
name="PM2.5",
unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
state_class=STATE_CLASS_MEASUREMENT,
),
GiosSensorEntityDescription(
key=ATTR_SO2,
name="SO2",
unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
state_class=STATE_CLASS_MEASUREMENT,
),
)

View File

@ -107,7 +107,7 @@ class GiosSensor(CoordinatorEntity, SensorEntity):
return self._attrs
@property
def state(self) -> StateType:
def native_value(self) -> StateType:
"""Return the state."""
state = getattr(self.coordinator.data, self.entity_description.key).value
assert self.entity_description.value is not None
@ -118,7 +118,7 @@ class GiosAqiSensor(GiosSensor):
"""Define an GIOS AQI sensor."""
@property
def state(self) -> StateType:
def native_value(self) -> StateType:
"""Return the state."""
return cast(
StateType, getattr(self.coordinator.data, self.entity_description.key).value

View File

@ -108,7 +108,7 @@ class GitHubSensor(SensorEntity):
return self._unique_id
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._state

View File

@ -88,7 +88,7 @@ class GitLabSensor(SensorEntity):
return self._name
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._state

View File

@ -65,12 +65,12 @@ class GitterSensor(SensorEntity):
return self._name
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._state
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self._unit_of_measurement

View File

@ -44,154 +44,154 @@ SENSOR_TYPES: tuple[GlancesSensorEntityDescription, ...] = (
key="disk_use_percent",
type="fs",
name_suffix="used percent",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
icon="mdi:harddisk",
),
GlancesSensorEntityDescription(
key="disk_use",
type="fs",
name_suffix="used",
unit_of_measurement=DATA_GIBIBYTES,
native_unit_of_measurement=DATA_GIBIBYTES,
icon="mdi:harddisk",
),
GlancesSensorEntityDescription(
key="disk_free",
type="fs",
name_suffix="free",
unit_of_measurement=DATA_GIBIBYTES,
native_unit_of_measurement=DATA_GIBIBYTES,
icon="mdi:harddisk",
),
GlancesSensorEntityDescription(
key="memory_use_percent",
type="mem",
name_suffix="RAM used percent",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
icon="mdi:memory",
),
GlancesSensorEntityDescription(
key="memory_use",
type="mem",
name_suffix="RAM used",
unit_of_measurement=DATA_MEBIBYTES,
native_unit_of_measurement=DATA_MEBIBYTES,
icon="mdi:memory",
),
GlancesSensorEntityDescription(
key="memory_free",
type="mem",
name_suffix="RAM free",
unit_of_measurement=DATA_MEBIBYTES,
native_unit_of_measurement=DATA_MEBIBYTES,
icon="mdi:memory",
),
GlancesSensorEntityDescription(
key="swap_use_percent",
type="memswap",
name_suffix="Swap used percent",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
icon="mdi:memory",
),
GlancesSensorEntityDescription(
key="swap_use",
type="memswap",
name_suffix="Swap used",
unit_of_measurement=DATA_GIBIBYTES,
native_unit_of_measurement=DATA_GIBIBYTES,
icon="mdi:memory",
),
GlancesSensorEntityDescription(
key="swap_free",
type="memswap",
name_suffix="Swap free",
unit_of_measurement=DATA_GIBIBYTES,
native_unit_of_measurement=DATA_GIBIBYTES,
icon="mdi:memory",
),
GlancesSensorEntityDescription(
key="processor_load",
type="load",
name_suffix="CPU load",
unit_of_measurement="15 min",
native_unit_of_measurement="15 min",
icon=CPU_ICON,
),
GlancesSensorEntityDescription(
key="process_running",
type="processcount",
name_suffix="Running",
unit_of_measurement="Count",
native_unit_of_measurement="Count",
icon=CPU_ICON,
),
GlancesSensorEntityDescription(
key="process_total",
type="processcount",
name_suffix="Total",
unit_of_measurement="Count",
native_unit_of_measurement="Count",
icon=CPU_ICON,
),
GlancesSensorEntityDescription(
key="process_thread",
type="processcount",
name_suffix="Thread",
unit_of_measurement="Count",
native_unit_of_measurement="Count",
icon=CPU_ICON,
),
GlancesSensorEntityDescription(
key="process_sleeping",
type="processcount",
name_suffix="Sleeping",
unit_of_measurement="Count",
native_unit_of_measurement="Count",
icon=CPU_ICON,
),
GlancesSensorEntityDescription(
key="cpu_use_percent",
type="cpu",
name_suffix="CPU used",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
icon=CPU_ICON,
),
GlancesSensorEntityDescription(
key="temperature_core",
type="sensors",
name_suffix="Temperature",
unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=TEMP_CELSIUS,
device_class=DEVICE_CLASS_TEMPERATURE,
),
GlancesSensorEntityDescription(
key="temperature_hdd",
type="sensors",
name_suffix="Temperature",
unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=TEMP_CELSIUS,
device_class=DEVICE_CLASS_TEMPERATURE,
),
GlancesSensorEntityDescription(
key="fan_speed",
type="sensors",
name_suffix="Fan speed",
unit_of_measurement="RPM",
native_unit_of_measurement="RPM",
icon="mdi:fan",
),
GlancesSensorEntityDescription(
key="battery",
type="sensors",
name_suffix="Charge",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
icon="mdi:battery",
),
GlancesSensorEntityDescription(
key="docker_active",
type="docker",
name_suffix="Containers active",
unit_of_measurement="",
native_unit_of_measurement="",
icon="mdi:docker",
),
GlancesSensorEntityDescription(
key="docker_cpu_use",
type="docker",
name_suffix="Containers CPU used",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
icon="mdi:docker",
),
GlancesSensorEntityDescription(
key="docker_memory_use",
type="docker",
name_suffix="Containers RAM used",
unit_of_measurement=DATA_MEBIBYTES,
native_unit_of_measurement=DATA_MEBIBYTES,
icon="mdi:docker",
),
)

View File

@ -83,7 +83,7 @@ class GlancesSensor(SensorEntity):
return self.glances_data.available
@property
def state(self):
def native_value(self):
"""Return the state of the resources."""
return self._state

View File

@ -48,12 +48,12 @@ class YetiSensor(YetiEntity):
self._attr_entity_registry_enabled_default = sensor.get(ATTR_DEFAULT_ENABLED)
self._attr_last_reset = sensor.get(ATTR_LAST_RESET)
self._attr_name = f"{name} {sensor.get(ATTR_NAME)}"
self._attr_native_unit_of_measurement = sensor.get(ATTR_UNIT_OF_MEASUREMENT)
self._attr_state_class = sensor.get(ATTR_STATE_CLASS)
self._attr_unique_id = f"{server_unique_id}/{sensor_name}"
self._attr_unit_of_measurement = sensor.get(ATTR_UNIT_OF_MEASUREMENT)
@property
def state(self) -> str | None:
def native_value(self) -> str | None:
"""Return the state."""
if self.api.data:
return self.api.data.get(self._condition)

View File

@ -72,7 +72,7 @@ class DoorSensorBattery(GoGoGate2Entity, SensorEntity):
return DEVICE_CLASS_BATTERY
@property
def state(self):
def native_value(self):
"""Return the state of the entity."""
door = self._get_door()
return door.voltage # This is a percentage, not an absolute voltage
@ -110,13 +110,13 @@ class DoorSensorTemperature(GoGoGate2Entity, SensorEntity):
return DEVICE_CLASS_TEMPERATURE
@property
def state(self):
def native_value(self):
"""Return the state of the entity."""
door = self._get_door()
return door.temperature
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit_of_measurement."""
return TEMP_CELSIUS

View File

@ -196,7 +196,7 @@ class GoogleTravelTimeSensor(SensorEntity):
await self.first_update()
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
if self._matrix is None:
return None
@ -250,7 +250,7 @@ class GoogleTravelTimeSensor(SensorEntity):
return res
@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

View File

@ -95,7 +95,7 @@ class GoogleWifiSensor(SensorEntity):
return self._var_icon
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self._var_units
@ -105,7 +105,7 @@ class GoogleWifiSensor(SensorEntity):
return self._api.available
@property
def state(self):
def native_value(self):
"""Return the state of the device."""
return self._state

View File

@ -84,7 +84,7 @@ class GpsdSensor(SensorEntity):
return self._name
@property
def state(self):
def native_value(self):
"""Return the state of GPSD."""
if self.agps_thread.data_stream.mode == 3:
return "3D Fix"

View File

@ -147,7 +147,7 @@ class CurrentSensor(GEMSensor):
"""Entity showing power usage on one channel of the monitor."""
_attr_icon = CURRENT_SENSOR_ICON
_attr_unit_of_measurement = UNIT_WATTS
_attr_native_unit_of_measurement = UNIT_WATTS
def __init__(self, monitor_serial_number, number, name, net_metering):
"""Construct the entity."""
@ -158,7 +158,7 @@ class CurrentSensor(GEMSensor):
return monitor.channels[self._number - 1]
@property
def state(self):
def native_value(self):
"""Return the current number of watts being used by the channel."""
if not self._sensor:
return None
@ -203,7 +203,7 @@ class PulseCounter(GEMSensor):
return monitor.pulse_counters[self._number - 1]
@property
def state(self):
def native_value(self):
"""Return the current rate of change for the given pulse counter."""
if not self._sensor or self._sensor.pulses_per_second is None:
return None
@ -225,7 +225,7 @@ class PulseCounter(GEMSensor):
return 3600
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement for this pulse counter."""
return f"{self._counted_quantity}/{self._time_unit}"
@ -253,7 +253,7 @@ class TemperatureSensor(GEMSensor):
return monitor.temperature_sensors[self._number - 1]
@property
def state(self):
def native_value(self):
"""Return the current temperature being reported by this sensor."""
if not self._sensor:
return None
@ -261,7 +261,7 @@ class TemperatureSensor(GEMSensor):
return self._sensor.temperature
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement for this sensor (user specified)."""
return self._unit
@ -270,7 +270,7 @@ class VoltageSensor(GEMSensor):
"""Entity showing voltage."""
_attr_icon = VOLTAGE_ICON
_attr_unit_of_measurement = ELECTRIC_POTENTIAL_VOLT
_attr_native_unit_of_measurement = ELECTRIC_POTENTIAL_VOLT
def __init__(self, monitor_serial_number, number, name):
"""Construct the entity."""
@ -281,7 +281,7 @@ class VoltageSensor(GEMSensor):
return monitor
@property
def state(self):
def native_value(self):
"""Return the current voltage being reported by this sensor."""
if not self._sensor:
return None

View File

@ -60,40 +60,40 @@ TOTAL_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="total_money_today",
name="Total money today",
api_key="plantMoneyText",
unit_of_measurement=CURRENCY_EURO,
native_unit_of_measurement=CURRENCY_EURO,
),
GrowattSensorEntityDescription(
key="total_money_total",
name="Money lifetime",
api_key="totalMoneyText",
unit_of_measurement=CURRENCY_EURO,
native_unit_of_measurement=CURRENCY_EURO,
),
GrowattSensorEntityDescription(
key="total_energy_today",
name="Energy Today",
api_key="todayEnergy",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="total_output_power",
name="Output Power",
api_key="invTodayPpv",
unit_of_measurement=POWER_WATT,
native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER,
),
GrowattSensorEntityDescription(
key="total_energy_output",
name="Lifetime energy output",
api_key="totalEnergy",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="total_maximum_output",
name="Maximum power",
api_key="nominalPower",
unit_of_measurement=POWER_WATT,
native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER,
),
)
@ -103,7 +103,7 @@ INVERTER_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="inverter_energy_today",
name="Energy today",
api_key="powerToday",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
precision=1,
),
@ -111,7 +111,7 @@ INVERTER_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="inverter_energy_total",
name="Lifetime energy output",
api_key="powerTotal",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
precision=1,
),
@ -119,7 +119,7 @@ INVERTER_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="inverter_voltage_input_1",
name="Input 1 voltage",
api_key="vpv1",
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
device_class=DEVICE_CLASS_VOLTAGE,
precision=2,
),
@ -127,7 +127,7 @@ INVERTER_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="inverter_amperage_input_1",
name="Input 1 Amperage",
api_key="ipv1",
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
device_class=DEVICE_CLASS_CURRENT,
precision=1,
),
@ -135,7 +135,7 @@ INVERTER_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="inverter_wattage_input_1",
name="Input 1 Wattage",
api_key="ppv1",
unit_of_measurement=POWER_WATT,
native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER,
precision=1,
),
@ -143,7 +143,7 @@ INVERTER_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="inverter_voltage_input_2",
name="Input 2 voltage",
api_key="vpv2",
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
device_class=DEVICE_CLASS_VOLTAGE,
precision=1,
),
@ -151,7 +151,7 @@ INVERTER_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="inverter_amperage_input_2",
name="Input 2 Amperage",
api_key="ipv2",
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
device_class=DEVICE_CLASS_CURRENT,
precision=1,
),
@ -159,7 +159,7 @@ INVERTER_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="inverter_wattage_input_2",
name="Input 2 Wattage",
api_key="ppv2",
unit_of_measurement=POWER_WATT,
native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER,
precision=1,
),
@ -167,7 +167,7 @@ INVERTER_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="inverter_voltage_input_3",
name="Input 3 voltage",
api_key="vpv3",
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
device_class=DEVICE_CLASS_VOLTAGE,
precision=1,
),
@ -175,7 +175,7 @@ INVERTER_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="inverter_amperage_input_3",
name="Input 3 Amperage",
api_key="ipv3",
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
device_class=DEVICE_CLASS_CURRENT,
precision=1,
),
@ -183,7 +183,7 @@ INVERTER_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="inverter_wattage_input_3",
name="Input 3 Wattage",
api_key="ppv3",
unit_of_measurement=POWER_WATT,
native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER,
precision=1,
),
@ -191,7 +191,7 @@ INVERTER_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="inverter_internal_wattage",
name="Internal wattage",
api_key="ppv",
unit_of_measurement=POWER_WATT,
native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER,
precision=1,
),
@ -199,7 +199,7 @@ INVERTER_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="inverter_reactive_voltage",
name="Reactive voltage",
api_key="vacr",
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
device_class=DEVICE_CLASS_VOLTAGE,
precision=1,
),
@ -207,7 +207,7 @@ INVERTER_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="inverter_inverter_reactive_amperage",
name="Reactive amperage",
api_key="iacr",
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
device_class=DEVICE_CLASS_CURRENT,
precision=1,
),
@ -215,14 +215,14 @@ INVERTER_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="inverter_frequency",
name="AC frequency",
api_key="fac",
unit_of_measurement=FREQUENCY_HERTZ,
native_unit_of_measurement=FREQUENCY_HERTZ,
precision=1,
),
GrowattSensorEntityDescription(
key="inverter_current_wattage",
name="Output power",
api_key="pac",
unit_of_measurement=POWER_WATT,
native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER,
precision=1,
),
@ -230,7 +230,7 @@ INVERTER_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="inverter_current_reactive_wattage",
name="Reactive wattage",
api_key="pacr",
unit_of_measurement=POWER_WATT,
native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER,
precision=1,
),
@ -238,7 +238,7 @@ INVERTER_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="inverter_ipm_temperature",
name="Intelligent Power Management temperature",
api_key="ipmTemperature",
unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=TEMP_CELSIUS,
device_class=DEVICE_CLASS_TEMPERATURE,
precision=1,
),
@ -246,7 +246,7 @@ INVERTER_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="inverter_temperature",
name="Temperature",
api_key="temperature",
unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=TEMP_CELSIUS,
device_class=DEVICE_CLASS_TEMPERATURE,
precision=1,
),
@ -257,118 +257,118 @@ STORAGE_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="storage_storage_production_today",
name="Storage production today",
api_key="eBatDisChargeToday",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="storage_storage_production_lifetime",
name="Lifetime Storage production",
api_key="eBatDisChargeTotal",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="storage_grid_discharge_today",
name="Grid discharged today",
api_key="eacDisChargeToday",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="storage_load_consumption_today",
name="Load consumption today",
api_key="eopDischrToday",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="storage_load_consumption_lifetime",
name="Lifetime load consumption",
api_key="eopDischrTotal",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="storage_grid_charged_today",
name="Grid charged today",
api_key="eacChargeToday",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="storage_charge_storage_lifetime",
name="Lifetime storaged charged",
api_key="eChargeTotal",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="storage_solar_production",
name="Solar power production",
api_key="ppv",
unit_of_measurement=POWER_WATT,
native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER,
),
GrowattSensorEntityDescription(
key="storage_battery_percentage",
name="Battery percentage",
api_key="capacity",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
device_class=DEVICE_CLASS_BATTERY,
),
GrowattSensorEntityDescription(
key="storage_power_flow",
name="Storage charging/ discharging(-ve)",
api_key="pCharge",
unit_of_measurement=POWER_WATT,
native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER,
),
GrowattSensorEntityDescription(
key="storage_load_consumption_solar_storage",
name="Load consumption(Solar + Storage)",
api_key="rateVA",
unit_of_measurement="VA",
native_unit_of_measurement="VA",
),
GrowattSensorEntityDescription(
key="storage_charge_today",
name="Charge today",
api_key="eChargeToday",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="storage_import_from_grid",
name="Import from grid",
api_key="pAcInPut",
unit_of_measurement=POWER_WATT,
native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER,
),
GrowattSensorEntityDescription(
key="storage_import_from_grid_today",
name="Import from grid today",
api_key="eToUserToday",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="storage_import_from_grid_total",
name="Import from grid total",
api_key="eToUserTotal",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="storage_load_consumption",
name="Load consumption",
api_key="outPutPower",
unit_of_measurement=POWER_WATT,
native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER,
),
GrowattSensorEntityDescription(
key="storage_grid_voltage",
name="AC input voltage",
api_key="vGrid",
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
device_class=DEVICE_CLASS_VOLTAGE,
precision=2,
),
@ -376,7 +376,7 @@ STORAGE_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="storage_pv_charging_voltage",
name="PV charging voltage",
api_key="vpv",
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
device_class=DEVICE_CLASS_VOLTAGE,
precision=2,
),
@ -384,14 +384,14 @@ STORAGE_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="storage_ac_input_frequency_out",
name="AC input frequency",
api_key="freqOutPut",
unit_of_measurement=FREQUENCY_HERTZ,
native_unit_of_measurement=FREQUENCY_HERTZ,
precision=2,
),
GrowattSensorEntityDescription(
key="storage_output_voltage",
name="Output voltage",
api_key="outPutVolt",
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
device_class=DEVICE_CLASS_VOLTAGE,
precision=2,
),
@ -399,14 +399,14 @@ STORAGE_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="storage_ac_output_frequency",
name="Ac output frequency",
api_key="freqGrid",
unit_of_measurement=FREQUENCY_HERTZ,
native_unit_of_measurement=FREQUENCY_HERTZ,
precision=2,
),
GrowattSensorEntityDescription(
key="storage_current_PV",
name="Solar charge current",
api_key="iAcCharge",
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
device_class=DEVICE_CLASS_CURRENT,
precision=2,
),
@ -414,7 +414,7 @@ STORAGE_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="storage_current_1",
name="Solar current to storage",
api_key="iChargePV1",
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
device_class=DEVICE_CLASS_CURRENT,
precision=2,
),
@ -422,7 +422,7 @@ STORAGE_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="storage_grid_amperage_input",
name="Grid charge current",
api_key="chgCurr",
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
device_class=DEVICE_CLASS_CURRENT,
precision=2,
),
@ -430,7 +430,7 @@ STORAGE_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="storage_grid_out_current",
name="Grid out current",
api_key="outPutCurrent",
unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
device_class=DEVICE_CLASS_CURRENT,
precision=2,
),
@ -438,7 +438,7 @@ STORAGE_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="storage_battery_voltage",
name="Battery voltage",
api_key="vBat",
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
device_class=DEVICE_CLASS_VOLTAGE,
precision=2,
),
@ -446,7 +446,7 @@ STORAGE_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="storage_load_percentage",
name="Load percentage",
api_key="loadPercent",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
device_class=DEVICE_CLASS_BATTERY,
precision=2,
),
@ -458,77 +458,77 @@ MIX_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="mix_statement_of_charge",
name="Statement of charge",
api_key="capacity",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
device_class=DEVICE_CLASS_BATTERY,
),
GrowattSensorEntityDescription(
key="mix_battery_charge_today",
name="Battery charged today",
api_key="eBatChargeToday",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="mix_battery_charge_lifetime",
name="Lifetime battery charged",
api_key="eBatChargeTotal",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="mix_battery_discharge_today",
name="Battery discharged today",
api_key="eBatDisChargeToday",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="mix_battery_discharge_lifetime",
name="Lifetime battery discharged",
api_key="eBatDisChargeTotal",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="mix_solar_generation_today",
name="Solar energy today",
api_key="epvToday",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="mix_solar_generation_lifetime",
name="Lifetime solar energy",
api_key="epvTotal",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="mix_battery_discharge_w",
name="Battery discharging W",
api_key="pDischarge1",
unit_of_measurement=POWER_WATT,
native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER,
),
GrowattSensorEntityDescription(
key="mix_battery_voltage",
name="Battery voltage",
api_key="vbat",
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
device_class=DEVICE_CLASS_VOLTAGE,
),
GrowattSensorEntityDescription(
key="mix_pv1_voltage",
name="PV1 voltage",
api_key="vpv1",
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
device_class=DEVICE_CLASS_VOLTAGE,
),
GrowattSensorEntityDescription(
key="mix_pv2_voltage",
name="PV2 voltage",
api_key="vpv2",
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
device_class=DEVICE_CLASS_VOLTAGE,
),
# Values from 'mix_totals' API call
@ -536,28 +536,28 @@ MIX_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="mix_load_consumption_today",
name="Load consumption today",
api_key="elocalLoadToday",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="mix_load_consumption_lifetime",
name="Lifetime load consumption",
api_key="elocalLoadTotal",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="mix_export_to_grid_today",
name="Export to grid today",
api_key="etoGridToday",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="mix_export_to_grid_lifetime",
name="Lifetime export to grid",
api_key="etogridTotal",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
# Values from 'mix_system_status' API call
@ -565,63 +565,63 @@ MIX_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="mix_battery_charge",
name="Battery charging",
api_key="chargePower",
unit_of_measurement=POWER_KILO_WATT,
native_unit_of_measurement=POWER_KILO_WATT,
device_class=DEVICE_CLASS_POWER,
),
GrowattSensorEntityDescription(
key="mix_load_consumption",
name="Load consumption",
api_key="pLocalLoad",
unit_of_measurement=POWER_KILO_WATT,
native_unit_of_measurement=POWER_KILO_WATT,
device_class=DEVICE_CLASS_POWER,
),
GrowattSensorEntityDescription(
key="mix_wattage_pv_1",
name="PV1 Wattage",
api_key="pPv1",
unit_of_measurement=POWER_KILO_WATT,
native_unit_of_measurement=POWER_KILO_WATT,
device_class=DEVICE_CLASS_POWER,
),
GrowattSensorEntityDescription(
key="mix_wattage_pv_2",
name="PV2 Wattage",
api_key="pPv2",
unit_of_measurement=POWER_KILO_WATT,
native_unit_of_measurement=POWER_KILO_WATT,
device_class=DEVICE_CLASS_POWER,
),
GrowattSensorEntityDescription(
key="mix_wattage_pv_all",
name="All PV Wattage",
api_key="ppv",
unit_of_measurement=POWER_KILO_WATT,
native_unit_of_measurement=POWER_KILO_WATT,
device_class=DEVICE_CLASS_POWER,
),
GrowattSensorEntityDescription(
key="mix_export_to_grid",
name="Export to grid",
api_key="pactogrid",
unit_of_measurement=POWER_KILO_WATT,
native_unit_of_measurement=POWER_KILO_WATT,
device_class=DEVICE_CLASS_POWER,
),
GrowattSensorEntityDescription(
key="mix_import_from_grid",
name="Import from grid",
api_key="pactouser",
unit_of_measurement=POWER_KILO_WATT,
native_unit_of_measurement=POWER_KILO_WATT,
device_class=DEVICE_CLASS_POWER,
),
GrowattSensorEntityDescription(
key="mix_battery_discharge_kw",
name="Battery discharging kW",
api_key="pdisCharge1",
unit_of_measurement=POWER_KILO_WATT,
native_unit_of_measurement=POWER_KILO_WATT,
device_class=DEVICE_CLASS_POWER,
),
GrowattSensorEntityDescription(
key="mix_grid_voltage",
name="Grid voltage",
api_key="vAc1",
unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
device_class=DEVICE_CLASS_VOLTAGE,
),
# Values from 'mix_detail' API call
@ -629,35 +629,35 @@ MIX_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="mix_system_production_today",
name="System production today (self-consumption + export)",
api_key="eCharge",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="mix_load_consumption_solar_today",
name="Load consumption today (solar)",
api_key="eChargeToday",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="mix_self_consumption_today",
name="Self consumption today (solar + battery)",
api_key="eChargeToday1",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="mix_load_consumption_battery_today",
name="Load consumption today (battery)",
api_key="echarge1",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
GrowattSensorEntityDescription(
key="mix_import_from_grid_today",
name="Import from grid today (load)",
api_key="etouser",
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
# This sensor is manually created using the most recent X-Axis value from the chartData
@ -665,7 +665,7 @@ MIX_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="mix_last_update",
name="Last Data Update",
api_key="lastdataupdate",
unit_of_measurement=None,
native_unit_of_measurement=None,
device_class=DEVICE_CLASS_TIMESTAMP,
),
# Values from 'dashboard_data' API call
@ -673,7 +673,7 @@ MIX_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
key="mix_import_from_grid_today_combined",
name="Import from grid today (load + charging)",
api_key="etouser_combined", # This id is not present in the raw API data, it is added by the sensor
unit_of_measurement=ENERGY_KILO_WATT_HOUR,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
),
)
@ -774,7 +774,7 @@ class GrowattInverter(SensorEntity):
self._attr_icon = "mdi:solar-power"
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
result = self.probe.get_data(self.entity_description.api_key)
if self.entity_description.precision is not None:

View File

@ -559,7 +559,7 @@ class GTFSDepartureSensor(SensorEntity):
return self._name
@property
def state(self) -> str | None: # type: ignore
def native_value(self) -> str | None: # type: ignore
"""Return the state of the sensor."""
return self._state

View File

@ -126,15 +126,15 @@ class PairedSensorSensor(PairedSensorEntity, SensorEntity):
"""Initialize."""
super().__init__(entry, coordinator, kind, name, device_class, icon)
self._attr_unit_of_measurement = unit
self._attr_native_unit_of_measurement = unit
@callback
def _async_update_from_latest_data(self) -> None:
"""Update the entity."""
if self._kind == SENSOR_KIND_BATTERY:
self._attr_state = self.coordinator.data["battery"]
self._attr_native_value = self.coordinator.data["battery"]
elif self._kind == SENSOR_KIND_TEMPERATURE:
self._attr_state = self.coordinator.data["temperature"]
self._attr_native_value = self.coordinator.data["temperature"]
class ValveControllerSensor(ValveControllerEntity, SensorEntity):
@ -153,7 +153,7 @@ class ValveControllerSensor(ValveControllerEntity, SensorEntity):
"""Initialize."""
super().__init__(entry, coordinators, kind, name, device_class, icon)
self._attr_unit_of_measurement = unit
self._attr_native_unit_of_measurement = unit
async def _async_continue_entity_setup(self) -> None:
"""Register API interest (and related tasks) when the entity is added."""
@ -167,11 +167,13 @@ class ValveControllerSensor(ValveControllerEntity, SensorEntity):
self._attr_available = self.coordinators[
API_SYSTEM_ONBOARD_SENSOR_STATUS
].last_update_success
self._attr_state = self.coordinators[API_SYSTEM_ONBOARD_SENSOR_STATUS].data[
"temperature"
]
self._attr_native_value = self.coordinators[
API_SYSTEM_ONBOARD_SENSOR_STATUS
].data["temperature"]
elif self._kind == SENSOR_KIND_UPTIME:
self._attr_available = self.coordinators[
API_SYSTEM_DIAGNOSTICS
].last_update_success
self._attr_state = self.coordinators[API_SYSTEM_DIAGNOSTICS].data["uptime"]
self._attr_native_value = self.coordinators[API_SYSTEM_DIAGNOSTICS].data[
"uptime"
]

View File

@ -155,12 +155,12 @@ class HabitipySensor(SensorEntity):
return f"{DOMAIN}_{self._name}_{self._sensor_name}"
@property
def state(self):
def native_value(self):
"""Return the state of the device."""
return self._state
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self._sensor_type.unit
@ -195,7 +195,7 @@ class HabitipyTaskSensor(SensorEntity):
return f"{DOMAIN}_{self._name}_{self._task_name}"
@property
def state(self):
def native_value(self):
"""Return the state of the device."""
return self._state
@ -220,6 +220,6 @@ class HabitipyTaskSensor(SensorEntity):
return attrs
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self._task_type.unit

View File

@ -39,7 +39,7 @@ class HassioAddonSensor(HassioAddonEntity, SensorEntity):
"""Sensor to track a Hass.io add-on attribute."""
@property
def state(self) -> str:
def native_value(self) -> str:
"""Return state of entity."""
return self.addon_info[self.attribute_name]
@ -48,6 +48,6 @@ class HassioOSSensor(HassioOSEntity, SensorEntity):
"""Sensor to track a Hass.io add-on attribute."""
@property
def state(self) -> str:
def native_value(self) -> str:
"""Return state of entity."""
return self.os_info[self.attribute_name]

View File

@ -69,12 +69,12 @@ class HaveIBeenPwnedSensor(SensorEntity):
return f"Breaches {self._email}"
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self._unit_of_measurement
@property
def state(self):
def native_value(self):
"""Return the state of the device."""
return self._state

View File

@ -78,7 +78,7 @@ class HddTempSensor(SensorEntity):
return self._name
@property
def state(self):
def native_value(self):
"""Return the state of the device."""
return self._state
@ -88,7 +88,7 @@ class HddTempSensor(SensorEntity):
return DEVICE_CLASS_TEMPERATURE
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self._unit

View File

@ -256,7 +256,7 @@ class HERETravelTimeSensor(SensorEntity):
)
@property
def state(self) -> str | None:
def native_value(self) -> str | None:
"""Return the state of the sensor."""
if self._here_data.traffic_mode and self._here_data.traffic_time is not None:
return str(round(self._here_data.traffic_time / 60))
@ -292,7 +292,7 @@ class HERETravelTimeSensor(SensorEntity):
return res
@property
def unit_of_measurement(self) -> str:
def native_unit_of_measurement(self) -> str:
"""Return the unit this state is expressed in."""
return self._unit_of_measurement

View File

@ -153,7 +153,7 @@ class HistoryStatsSensor(SensorEntity):
return self._name
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
if self.value is None or self.count is None:
return None
@ -168,7 +168,7 @@ class HistoryStatsSensor(SensorEntity):
return 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

View File

@ -57,7 +57,7 @@ class HiveSensorEntity(HiveEntity, SensorEntity):
return DEVICETYPE[self.device["hiveType"]].get("type")
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement."""
return DEVICETYPE[self.device["hiveType"]].get("unit")
@ -67,7 +67,7 @@ class HiveSensorEntity(HiveEntity, SensorEntity):
return self.device["haName"]
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self.device["status"]["state"]

View File

@ -42,7 +42,7 @@ class HomeConnectSensor(HomeConnectEntity, SensorEntity):
self._sign = sign
@property
def state(self):
def native_value(self):
"""Return true if the binary sensor is on."""
return self._state
@ -83,7 +83,7 @@ class HomeConnectSensor(HomeConnectEntity, SensorEntity):
_LOGGER.debug("Updated, new state: %s", self._state)
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement."""
return self._unit

View File

@ -79,7 +79,7 @@ class HomeKitHumiditySensor(HomeKitEntity, SensorEntity):
"""Representation of a Homekit humidity sensor."""
_attr_device_class = DEVICE_CLASS_HUMIDITY
_attr_unit_of_measurement = PERCENTAGE
_attr_native_unit_of_measurement = PERCENTAGE
def get_characteristic_types(self):
"""Define the homekit characteristics the entity is tracking."""
@ -96,7 +96,7 @@ class HomeKitHumiditySensor(HomeKitEntity, SensorEntity):
return HUMIDITY_ICON
@property
def state(self):
def native_value(self):
"""Return the current humidity."""
return self.service.value(CharacteristicsTypes.RELATIVE_HUMIDITY_CURRENT)
@ -105,7 +105,7 @@ class HomeKitTemperatureSensor(HomeKitEntity, SensorEntity):
"""Representation of a Homekit temperature sensor."""
_attr_device_class = DEVICE_CLASS_TEMPERATURE
_attr_unit_of_measurement = TEMP_CELSIUS
_attr_native_unit_of_measurement = TEMP_CELSIUS
def get_characteristic_types(self):
"""Define the homekit characteristics the entity is tracking."""
@ -122,7 +122,7 @@ class HomeKitTemperatureSensor(HomeKitEntity, SensorEntity):
return TEMP_C_ICON
@property
def state(self):
def native_value(self):
"""Return the current temperature in Celsius."""
return self.service.value(CharacteristicsTypes.TEMPERATURE_CURRENT)
@ -131,7 +131,7 @@ class HomeKitLightSensor(HomeKitEntity, SensorEntity):
"""Representation of a Homekit light level sensor."""
_attr_device_class = DEVICE_CLASS_ILLUMINANCE
_attr_unit_of_measurement = LIGHT_LUX
_attr_native_unit_of_measurement = LIGHT_LUX
def get_characteristic_types(self):
"""Define the homekit characteristics the entity is tracking."""
@ -148,7 +148,7 @@ class HomeKitLightSensor(HomeKitEntity, SensorEntity):
return BRIGHTNESS_ICON
@property
def state(self):
def native_value(self):
"""Return the current light level in lux."""
return self.service.value(CharacteristicsTypes.LIGHT_LEVEL_CURRENT)
@ -157,7 +157,7 @@ class HomeKitCarbonDioxideSensor(HomeKitEntity, SensorEntity):
"""Representation of a Homekit Carbon Dioxide sensor."""
_attr_icon = CO2_ICON
_attr_unit_of_measurement = CONCENTRATION_PARTS_PER_MILLION
_attr_native_unit_of_measurement = CONCENTRATION_PARTS_PER_MILLION
def get_characteristic_types(self):
"""Define the homekit characteristics the entity is tracking."""
@ -169,7 +169,7 @@ class HomeKitCarbonDioxideSensor(HomeKitEntity, SensorEntity):
return f"{super().name} CO2"
@property
def state(self):
def native_value(self):
"""Return the current CO2 level in ppm."""
return self.service.value(CharacteristicsTypes.CARBON_DIOXIDE_LEVEL)
@ -178,7 +178,7 @@ class HomeKitBatterySensor(HomeKitEntity, SensorEntity):
"""Representation of a Homekit battery sensor."""
_attr_device_class = DEVICE_CLASS_BATTERY
_attr_unit_of_measurement = PERCENTAGE
_attr_native_unit_of_measurement = PERCENTAGE
def get_characteristic_types(self):
"""Define the homekit characteristics the entity is tracking."""
@ -229,7 +229,7 @@ class HomeKitBatterySensor(HomeKitEntity, SensorEntity):
return self.service.value(CharacteristicsTypes.CHARGING_STATE) == 1
@property
def state(self):
def native_value(self):
"""Return the current battery level percentage."""
return self.service.value(CharacteristicsTypes.BATTERY_LEVEL)
@ -281,7 +281,7 @@ class SimpleSensor(CharacteristicEntity, SensorEntity):
return self._state_class
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return units for the sensor."""
return self._unit
@ -296,7 +296,7 @@ class SimpleSensor(CharacteristicEntity, SensorEntity):
return f"{super().name} - {self._name}"
@property
def state(self):
def native_value(self):
"""Return the current sensor value."""
return self._char.value

View File

@ -107,7 +107,7 @@ class HMSensor(HMDevice, SensorEntity):
"""Representation of a HomeMatic sensor."""
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
# Does a cast exist for this class?
name = self._hmdevice.__class__.__name__
@ -118,7 +118,7 @@ class HMSensor(HMDevice, SensorEntity):
return self._hm_get_state()
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any."""
return HM_UNIT_HA_CAST.get(self._state)

View File

@ -137,12 +137,12 @@ class HomematicipAccesspointDutyCycle(HomematicipGenericEntity, SensorEntity):
return "mdi:access-point-network"
@property
def state(self) -> float:
def native_value(self) -> float:
"""Return the state of the access point."""
return self._device.dutyCycleLevel
@property
def unit_of_measurement(self) -> str:
def native_unit_of_measurement(self) -> str:
"""Return the unit this state is expressed in."""
return PERCENTAGE
@ -164,14 +164,14 @@ class HomematicipHeatingThermostat(HomematicipGenericEntity, SensorEntity):
return "mdi:radiator"
@property
def state(self) -> int:
def native_value(self) -> int:
"""Return the state of the radiator valve."""
if self._device.valveState != ValveState.ADAPTION_DONE:
return self._device.valveState
return round(self._device.valvePosition * 100)
@property
def unit_of_measurement(self) -> str:
def native_unit_of_measurement(self) -> str:
"""Return the unit this state is expressed in."""
return PERCENTAGE
@ -189,12 +189,12 @@ class HomematicipHumiditySensor(HomematicipGenericEntity, SensorEntity):
return DEVICE_CLASS_HUMIDITY
@property
def state(self) -> int:
def native_value(self) -> int:
"""Return the state."""
return self._device.humidity
@property
def unit_of_measurement(self) -> str:
def native_unit_of_measurement(self) -> str:
"""Return the unit this state is expressed in."""
return PERCENTAGE
@ -212,7 +212,7 @@ class HomematicipTemperatureSensor(HomematicipGenericEntity, SensorEntity):
return DEVICE_CLASS_TEMPERATURE
@property
def state(self) -> float:
def native_value(self) -> float:
"""Return the state."""
if hasattr(self._device, "valveActualTemperature"):
return self._device.valveActualTemperature
@ -220,7 +220,7 @@ class HomematicipTemperatureSensor(HomematicipGenericEntity, SensorEntity):
return self._device.actualTemperature
@property
def unit_of_measurement(self) -> str:
def native_unit_of_measurement(self) -> str:
"""Return the unit this state is expressed in."""
return TEMP_CELSIUS
@ -249,7 +249,7 @@ class HomematicipIlluminanceSensor(HomematicipGenericEntity, SensorEntity):
return DEVICE_CLASS_ILLUMINANCE
@property
def state(self) -> float:
def native_value(self) -> float:
"""Return the state."""
if hasattr(self._device, "averageIllumination"):
return self._device.averageIllumination
@ -257,7 +257,7 @@ class HomematicipIlluminanceSensor(HomematicipGenericEntity, SensorEntity):
return self._device.illumination
@property
def unit_of_measurement(self) -> str:
def native_unit_of_measurement(self) -> str:
"""Return the unit this state is expressed in."""
return LIGHT_LUX
@ -287,12 +287,12 @@ class HomematicipPowerSensor(HomematicipGenericEntity, SensorEntity):
return DEVICE_CLASS_POWER
@property
def state(self) -> float:
def native_value(self) -> float:
"""Return the power consumption value."""
return self._device.currentPowerConsumption
@property
def unit_of_measurement(self) -> str:
def native_unit_of_measurement(self) -> str:
"""Return the unit this state is expressed in."""
return POWER_WATT
@ -305,12 +305,12 @@ class HomematicipWindspeedSensor(HomematicipGenericEntity, SensorEntity):
super().__init__(hap, device, post="Windspeed")
@property
def state(self) -> float:
def native_value(self) -> float:
"""Return the wind speed value."""
return self._device.windSpeed
@property
def unit_of_measurement(self) -> str:
def native_unit_of_measurement(self) -> str:
"""Return the unit this state is expressed in."""
return SPEED_KILOMETERS_PER_HOUR
@ -338,12 +338,12 @@ class HomematicipTodayRainSensor(HomematicipGenericEntity, SensorEntity):
super().__init__(hap, device, post="Today Rain")
@property
def state(self) -> float:
def native_value(self) -> float:
"""Return the today's rain value."""
return round(self._device.todayRainCounter, 2)
@property
def unit_of_measurement(self) -> str:
def native_unit_of_measurement(self) -> str:
"""Return the unit this state is expressed in."""
return LENGTH_MILLIMETERS
@ -352,7 +352,7 @@ class HomematicipPassageDetectorDeltaCounter(HomematicipGenericEntity, SensorEnt
"""Representation of the HomematicIP passage detector delta counter."""
@property
def state(self) -> int:
def native_value(self) -> int:
"""Return the passage detector delta counter value."""
return self._device.leftRightCounterDelta

View File

@ -133,12 +133,12 @@ class HpIloSensor(SensorEntity):
return self._name
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement of the sensor."""
return self._unit_of_measurement
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._state

View File

@ -98,12 +98,12 @@ class HTU21DSensor(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 of the sensor."""
return self._unit_of_measurement

View File

@ -426,7 +426,7 @@ class HuaweiLteSensor(HuaweiLteBaseEntity, SensorEntity):
return f"{self.key}.{self.item}"
@property
def state(self) -> StateType:
def native_value(self) -> StateType:
"""Return sensor state."""
return self._state
@ -436,7 +436,7 @@ class HuaweiLteSensor(HuaweiLteBaseEntity, SensorEntity):
return self.meta.device_class
@property
def unit_of_measurement(self) -> str | None:
def native_unit_of_measurement(self) -> str | None:
"""Return sensor's unit of measurement."""
return self.meta.unit or self._unit

View File

@ -42,10 +42,10 @@ class HueLightLevel(GenericHueGaugeSensorEntity):
"""The light level sensor entity for a Hue motion sensor device."""
_attr_device_class = DEVICE_CLASS_ILLUMINANCE
_attr_unit_of_measurement = LIGHT_LUX
_attr_native_unit_of_measurement = LIGHT_LUX
@property
def state(self):
def native_value(self):
"""Return the state of the device."""
if self.sensor.lightlevel is None:
return None
@ -78,10 +78,10 @@ class HueTemperature(GenericHueGaugeSensorEntity):
_attr_device_class = DEVICE_CLASS_TEMPERATURE
_attr_state_class = STATE_CLASS_MEASUREMENT
_attr_unit_of_measurement = TEMP_CELSIUS
_attr_native_unit_of_measurement = TEMP_CELSIUS
@property
def state(self):
def native_value(self):
"""Return the state of the device."""
if self.sensor.temperature is None:
return None
@ -94,7 +94,7 @@ class HueBattery(GenericHueSensor, SensorEntity):
_attr_device_class = DEVICE_CLASS_BATTERY
_attr_state_class = STATE_CLASS_MEASUREMENT
_attr_unit_of_measurement = PERCENTAGE
_attr_native_unit_of_measurement = PERCENTAGE
@property
def unique_id(self):
@ -102,7 +102,7 @@ class HueBattery(GenericHueSensor, SensorEntity):
return f"{self.sensor.uniqueid}-battery"
@property
def state(self):
def native_value(self):
"""Return the state of the battery."""
return self.sensor.battery

View File

@ -75,7 +75,7 @@ class HuisbaasjeSensor(CoordinatorEntity, SensorEntity):
return self._icon
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
if self.coordinator.data[self._source_type][self._sensor_type] is not None:
return round(
@ -85,7 +85,7 @@ class HuisbaasjeSensor(CoordinatorEntity, SensorEntity):
return None
@property
def unit_of_measurement(self) -> str:
def native_unit_of_measurement(self) -> str:
"""Return the unit of measurement."""
return self._unit_of_measurement

View File

@ -50,7 +50,7 @@ class PowerViewShadeBatterySensor(ShadeEntity, SensorEntity):
"""Representation of an shade battery charge sensor."""
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the unit of measurement."""
return PERCENTAGE
@ -70,7 +70,7 @@ class PowerViewShadeBatterySensor(ShadeEntity, SensorEntity):
return f"{self._unique_id}_charge"
@property
def state(self):
def native_value(self):
"""Get the current value in percentage."""
return round(
self._shade.raw_data[SHADE_BATTERY_LEVEL] / SHADE_BATTERY_LEVEL_MAX * 100

View File

@ -177,7 +177,7 @@ class HVVDepartureSensor(SensorEntity):
return self._name
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._state

View File

@ -40,12 +40,12 @@ class HydrawiseSensor(HydrawiseEntity, SensorEntity):
"""A sensor implementation for Hydrawise device."""
@property
def state(self):
def native_value(self):
"""Return the state of the sensor."""
return self._state
@property
def unit_of_measurement(self):
def native_unit_of_measurement(self):
"""Return the units of measurement."""
return DEVICE_MAP[self._sensor_type][
DEVICE_MAP_INDEX.index("UNIT_OF_MEASURE_INDEX")

View File

@ -83,6 +83,7 @@ async def test_single_ban(hass):
"""Test that log is parsed correctly for single ban."""
log_parser = BanLogParser("/test/fail2ban.log")
sensor = BanSensor("fail2ban", "jail_one", log_parser)
sensor.hass = hass
assert sensor.name == "fail2ban jail_one"
mock_fh = mock_open(read_data=fake_log("single_ban"))
with patch("homeassistant.components.fail2ban.sensor.open", mock_fh, create=True):
@ -97,6 +98,7 @@ async def test_ipv6_ban(hass):
"""Test that log is parsed correctly for IPV6 bans."""
log_parser = BanLogParser("/test/fail2ban.log")
sensor = BanSensor("fail2ban", "jail_one", log_parser)
sensor.hass = hass
assert sensor.name == "fail2ban jail_one"
mock_fh = mock_open(read_data=fake_log("ipv6_ban"))
with patch("homeassistant.components.fail2ban.sensor.open", mock_fh, create=True):
@ -111,6 +113,7 @@ async def test_multiple_ban(hass):
"""Test that log is parsed correctly for multiple ban."""
log_parser = BanLogParser("/test/fail2ban.log")
sensor = BanSensor("fail2ban", "jail_one", log_parser)
sensor.hass = hass
assert sensor.name == "fail2ban jail_one"
mock_fh = mock_open(read_data=fake_log("multi_ban"))
with patch("homeassistant.components.fail2ban.sensor.open", mock_fh, create=True):
@ -131,6 +134,7 @@ async def test_unban_all(hass):
"""Test that log is parsed correctly when unbanning."""
log_parser = BanLogParser("/test/fail2ban.log")
sensor = BanSensor("fail2ban", "jail_one", log_parser)
sensor.hass = hass
assert sensor.name == "fail2ban jail_one"
mock_fh = mock_open(read_data=fake_log("unban_all"))
with patch("homeassistant.components.fail2ban.sensor.open", mock_fh, create=True):
@ -148,6 +152,7 @@ async def test_unban_one(hass):
"""Test that log is parsed correctly when unbanning one ip."""
log_parser = BanLogParser("/test/fail2ban.log")
sensor = BanSensor("fail2ban", "jail_one", log_parser)
sensor.hass = hass
assert sensor.name == "fail2ban jail_one"
mock_fh = mock_open(read_data=fake_log("unban_one"))
with patch("homeassistant.components.fail2ban.sensor.open", mock_fh, create=True):
@ -166,6 +171,8 @@ async def test_multi_jail(hass):
log_parser = BanLogParser("/test/fail2ban.log")
sensor1 = BanSensor("fail2ban", "jail_one", log_parser)
sensor2 = BanSensor("fail2ban", "jail_two", log_parser)
sensor1.hass = hass
sensor2.hass = hass
assert sensor1.name == "fail2ban jail_one"
assert sensor2.name == "fail2ban jail_two"
mock_fh = mock_open(read_data=fake_log("multi_jail"))
@ -185,6 +192,7 @@ async def test_ban_active_after_update(hass):
"""Test that ban persists after subsequent update."""
log_parser = BanLogParser("/test/fail2ban.log")
sensor = BanSensor("fail2ban", "jail_one", log_parser)
sensor.hass = hass
assert sensor.name == "fail2ban jail_one"
mock_fh = mock_open(read_data=fake_log("single_ban"))
with patch("homeassistant.components.fail2ban.sensor.open", mock_fh, create=True):

View File

@ -68,7 +68,7 @@ async def test_setup_get(hass, requests_mock):
assert_setup_component(6, "sensor")
def setup_api(data, requests_mock):
def setup_api(hass, data, requests_mock):
"""Set up API with fake data."""
resource = f"http://localhost{google_wifi.ENDPOINT}"
now = datetime(1970, month=1, day=1)
@ -84,6 +84,10 @@ def setup_api(data, requests_mock):
"units": cond_list[1],
"icon": cond_list[2],
}
for name in sensor_dict:
sensor = sensor_dict[name]["sensor"]
sensor.hass = hass
return api, sensor_dict
@ -96,7 +100,7 @@ def fake_delay(hass, ha_delay):
def test_name(requests_mock):
"""Test the name."""
api, sensor_dict = setup_api(MOCK_DATA, requests_mock)
api, sensor_dict = setup_api(None, MOCK_DATA, requests_mock)
for name in sensor_dict:
sensor = sensor_dict[name]["sensor"]
test_name = sensor_dict[name]["name"]
@ -105,7 +109,7 @@ def test_name(requests_mock):
def test_unit_of_measurement(requests_mock):
"""Test the unit of measurement."""
api, sensor_dict = setup_api(MOCK_DATA, requests_mock)
api, sensor_dict = setup_api(None, MOCK_DATA, requests_mock)
for name in sensor_dict:
sensor = sensor_dict[name]["sensor"]
assert sensor_dict[name]["units"] == sensor.unit_of_measurement
@ -113,7 +117,7 @@ def test_unit_of_measurement(requests_mock):
def test_icon(requests_mock):
"""Test the icon."""
api, sensor_dict = setup_api(MOCK_DATA, requests_mock)
api, sensor_dict = setup_api(None, MOCK_DATA, requests_mock)
for name in sensor_dict:
sensor = sensor_dict[name]["sensor"]
assert sensor_dict[name]["icon"] == sensor.icon
@ -121,7 +125,7 @@ def test_icon(requests_mock):
def test_state(hass, requests_mock):
"""Test the initial state."""
api, sensor_dict = setup_api(MOCK_DATA, requests_mock)
api, sensor_dict = setup_api(hass, MOCK_DATA, requests_mock)
now = datetime(1970, month=1, day=1)
with patch("homeassistant.util.dt.now", return_value=now):
for name in sensor_dict:
@ -140,7 +144,7 @@ def test_state(hass, requests_mock):
def test_update_when_value_is_none(hass, requests_mock):
"""Test state gets updated to unknown when sensor returns no data."""
api, sensor_dict = setup_api(None, requests_mock)
api, sensor_dict = setup_api(hass, None, requests_mock)
for name in sensor_dict:
sensor = sensor_dict[name]["sensor"]
fake_delay(hass, 2)
@ -150,7 +154,7 @@ def test_update_when_value_is_none(hass, requests_mock):
def test_update_when_value_changed(hass, requests_mock):
"""Test state gets updated when sensor returns a new status."""
api, sensor_dict = setup_api(MOCK_DATA_NEXT, requests_mock)
api, sensor_dict = setup_api(hass, MOCK_DATA_NEXT, requests_mock)
now = datetime(1970, month=1, day=1)
with patch("homeassistant.util.dt.now", return_value=now):
for name in sensor_dict:
@ -173,7 +177,7 @@ def test_update_when_value_changed(hass, requests_mock):
def test_when_api_data_missing(hass, requests_mock):
"""Test state logs an error when data is missing."""
api, sensor_dict = setup_api(MOCK_DATA_MISSING, requests_mock)
api, sensor_dict = setup_api(hass, MOCK_DATA_MISSING, requests_mock)
now = datetime(1970, month=1, day=1)
with patch("homeassistant.util.dt.now", return_value=now):
for name in sensor_dict:
@ -183,12 +187,12 @@ def test_when_api_data_missing(hass, requests_mock):
assert sensor.state == STATE_UNKNOWN
def test_update_when_unavailable(requests_mock):
def test_update_when_unavailable(hass, requests_mock):
"""Test state updates when Google Wifi unavailable."""
api, sensor_dict = setup_api(None, requests_mock)
api, sensor_dict = setup_api(hass, None, requests_mock)
api.update = Mock(
"google_wifi.GoogleWifiAPI.update",
side_effect=update_side_effect(requests_mock),
side_effect=update_side_effect(hass, requests_mock),
)
for name in sensor_dict:
sensor = sensor_dict[name]["sensor"]
@ -196,8 +200,8 @@ def test_update_when_unavailable(requests_mock):
assert sensor.state is None
def update_side_effect(requests_mock):
def update_side_effect(hass, requests_mock):
"""Mock representation of update function."""
api, sensor_dict = setup_api(MOCK_DATA, requests_mock)
api, sensor_dict = setup_api(hass, MOCK_DATA, requests_mock)
api.data = None
api.available = False