mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
Drop some unnecessary lambdas in powerwall (#122936)
This commit is contained in:
parent
4aacec2de7
commit
c7f863a141
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from operator import attrgetter, methodcaller
|
||||||
from typing import TYPE_CHECKING, Generic, TypeVar
|
from typing import TYPE_CHECKING, Generic, TypeVar
|
||||||
|
|
||||||
from tesla_powerwall import GridState, MeterResponse, MeterType
|
from tesla_powerwall import GridState, MeterResponse, MeterType
|
||||||
@ -58,11 +59,6 @@ def _get_meter_frequency(meter: MeterResponse) -> float:
|
|||||||
return round(meter.frequency, 1)
|
return round(meter.frequency, 1)
|
||||||
|
|
||||||
|
|
||||||
def _get_meter_total_current(meter: MeterResponse) -> float:
|
|
||||||
"""Get the current value in A."""
|
|
||||||
return meter.get_instant_total_current()
|
|
||||||
|
|
||||||
|
|
||||||
def _get_meter_average_voltage(meter: MeterResponse) -> float:
|
def _get_meter_average_voltage(meter: MeterResponse) -> float:
|
||||||
"""Get the current value in V."""
|
"""Get the current value in V."""
|
||||||
return round(meter.instant_average_voltage, 1)
|
return round(meter.instant_average_voltage, 1)
|
||||||
@ -93,7 +89,7 @@ POWERWALL_INSTANT_SENSORS = (
|
|||||||
device_class=SensorDeviceClass.CURRENT,
|
device_class=SensorDeviceClass.CURRENT,
|
||||||
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
value_fn=_get_meter_total_current,
|
value_fn=methodcaller("get_instant_total_current"),
|
||||||
),
|
),
|
||||||
PowerwallSensorEntityDescription[MeterResponse, float](
|
PowerwallSensorEntityDescription[MeterResponse, float](
|
||||||
key="instant_voltage",
|
key="instant_voltage",
|
||||||
@ -132,7 +128,7 @@ BATTERY_INSTANT_SENSORS: list[PowerwallSensorEntityDescription] = [
|
|||||||
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
|
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
|
||||||
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||||
suggested_display_precision=1,
|
suggested_display_precision=1,
|
||||||
value_fn=lambda battery_data: battery_data.capacity,
|
value_fn=attrgetter("capacity"),
|
||||||
),
|
),
|
||||||
PowerwallSensorEntityDescription[BatteryResponse, float | None](
|
PowerwallSensorEntityDescription[BatteryResponse, float | None](
|
||||||
key="battery_instant_voltage",
|
key="battery_instant_voltage",
|
||||||
@ -170,7 +166,7 @@ BATTERY_INSTANT_SENSORS: list[PowerwallSensorEntityDescription] = [
|
|||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
device_class=SensorDeviceClass.POWER,
|
device_class=SensorDeviceClass.POWER,
|
||||||
native_unit_of_measurement=UnitOfPower.WATT,
|
native_unit_of_measurement=UnitOfPower.WATT,
|
||||||
value_fn=lambda battery_data: battery_data.p_out,
|
value_fn=attrgetter("p_out"),
|
||||||
),
|
),
|
||||||
PowerwallSensorEntityDescription[BatteryResponse, float | None](
|
PowerwallSensorEntityDescription[BatteryResponse, float | None](
|
||||||
key="battery_export",
|
key="battery_export",
|
||||||
@ -181,7 +177,7 @@ BATTERY_INSTANT_SENSORS: list[PowerwallSensorEntityDescription] = [
|
|||||||
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
|
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
|
||||||
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||||
suggested_display_precision=0,
|
suggested_display_precision=0,
|
||||||
value_fn=lambda battery_data: battery_data.energy_discharged,
|
value_fn=attrgetter("energy_discharged"),
|
||||||
),
|
),
|
||||||
PowerwallSensorEntityDescription[BatteryResponse, float | None](
|
PowerwallSensorEntityDescription[BatteryResponse, float | None](
|
||||||
key="battery_import",
|
key="battery_import",
|
||||||
@ -192,7 +188,7 @@ BATTERY_INSTANT_SENSORS: list[PowerwallSensorEntityDescription] = [
|
|||||||
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
|
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
|
||||||
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||||
suggested_display_precision=0,
|
suggested_display_precision=0,
|
||||||
value_fn=lambda battery_data: battery_data.energy_charged,
|
value_fn=attrgetter("energy_charged"),
|
||||||
),
|
),
|
||||||
PowerwallSensorEntityDescription[BatteryResponse, int](
|
PowerwallSensorEntityDescription[BatteryResponse, int](
|
||||||
key="battery_remaining",
|
key="battery_remaining",
|
||||||
@ -203,7 +199,7 @@ BATTERY_INSTANT_SENSORS: list[PowerwallSensorEntityDescription] = [
|
|||||||
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
|
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
|
||||||
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
|
||||||
suggested_display_precision=1,
|
suggested_display_precision=1,
|
||||||
value_fn=lambda battery_data: battery_data.energy_remaining,
|
value_fn=attrgetter("energy_remaining"),
|
||||||
),
|
),
|
||||||
PowerwallSensorEntityDescription[BatteryResponse, str](
|
PowerwallSensorEntityDescription[BatteryResponse, str](
|
||||||
key="grid_state",
|
key="grid_state",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user