mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Adjust charging_power unit (#56167)
This commit is contained in:
parent
30c25d4448
commit
0d842a8f01
@ -20,9 +20,11 @@ from homeassistant.components.sensor import (
|
|||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
DEVICE_CLASS_BATTERY,
|
DEVICE_CLASS_BATTERY,
|
||||||
|
DEVICE_CLASS_CURRENT,
|
||||||
DEVICE_CLASS_ENERGY,
|
DEVICE_CLASS_ENERGY,
|
||||||
DEVICE_CLASS_POWER,
|
DEVICE_CLASS_POWER,
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
DEVICE_CLASS_TEMPERATURE,
|
||||||
|
ELECTRIC_CURRENT_AMPERE,
|
||||||
ENERGY_KILO_WATT_HOUR,
|
ENERGY_KILO_WATT_HOUR,
|
||||||
LENGTH_KILOMETERS,
|
LENGTH_KILOMETERS,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
@ -39,6 +41,7 @@ from .const import DEVICE_CLASS_CHARGE_STATE, DEVICE_CLASS_PLUG_STATE, DOMAIN
|
|||||||
from .renault_coordinator import T
|
from .renault_coordinator import T
|
||||||
from .renault_entities import RenaultDataEntity, RenaultEntityDescription
|
from .renault_entities import RenaultDataEntity, RenaultEntityDescription
|
||||||
from .renault_hub import RenaultHub
|
from .renault_hub import RenaultHub
|
||||||
|
from .renault_vehicle import RenaultVehicleProxy
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -56,6 +59,7 @@ class RenaultSensorEntityDescription(
|
|||||||
"""Class describing Renault sensor entities."""
|
"""Class describing Renault sensor entities."""
|
||||||
|
|
||||||
icon_lambda: Callable[[RenaultSensor[T]], str] | None = None
|
icon_lambda: Callable[[RenaultSensor[T]], str] | None = None
|
||||||
|
condition_lambda: Callable[[RenaultVehicleProxy], bool] | None = None
|
||||||
requires_fuel: bool = False
|
requires_fuel: bool = False
|
||||||
value_lambda: Callable[[RenaultSensor[T]], StateType] | None = None
|
value_lambda: Callable[[RenaultSensor[T]], StateType] | None = None
|
||||||
|
|
||||||
@ -73,6 +77,7 @@ async def async_setup_entry(
|
|||||||
for description in SENSOR_TYPES
|
for description in SENSOR_TYPES
|
||||||
if description.coordinator in vehicle.coordinators
|
if description.coordinator in vehicle.coordinators
|
||||||
and (not description.requires_fuel or vehicle.details.uses_fuel())
|
and (not description.requires_fuel or vehicle.details.uses_fuel())
|
||||||
|
and (not description.condition_lambda or description.condition_lambda(vehicle))
|
||||||
]
|
]
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
@ -106,9 +111,7 @@ class RenaultSensor(RenaultDataEntity[T], SensorEntity):
|
|||||||
|
|
||||||
def _get_charging_power(entity: RenaultSensor[T]) -> StateType:
|
def _get_charging_power(entity: RenaultSensor[T]) -> StateType:
|
||||||
"""Return the charging_power of this entity."""
|
"""Return the charging_power of this entity."""
|
||||||
if entity.vehicle.details.reports_charging_power_in_watts():
|
return cast(float, entity.data) / 1000
|
||||||
return cast(float, entity.data) / 1000
|
|
||||||
return entity.data
|
|
||||||
|
|
||||||
|
|
||||||
def _get_charge_state_formatted(entity: RenaultSensor[T]) -> str | None:
|
def _get_charge_state_formatted(entity: RenaultSensor[T]) -> str | None:
|
||||||
@ -177,6 +180,18 @@ SENSOR_TYPES: tuple[RenaultSensorEntityDescription, ...] = (
|
|||||||
),
|
),
|
||||||
RenaultSensorEntityDescription(
|
RenaultSensorEntityDescription(
|
||||||
key="charging_power",
|
key="charging_power",
|
||||||
|
condition_lambda=lambda a: not a.details.reports_charging_power_in_watts(),
|
||||||
|
coordinator="battery",
|
||||||
|
data_key="chargingInstantaneousPower",
|
||||||
|
device_class=DEVICE_CLASS_CURRENT,
|
||||||
|
entity_class=RenaultSensor[KamereonVehicleBatteryStatusData],
|
||||||
|
name="Charging Power",
|
||||||
|
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||||
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
|
),
|
||||||
|
RenaultSensorEntityDescription(
|
||||||
|
key="charging_power",
|
||||||
|
condition_lambda=lambda a: a.details.reports_charging_power_in_watts(),
|
||||||
coordinator="battery",
|
coordinator="battery",
|
||||||
data_key="chargingInstantaneousPower",
|
data_key="chargingInstantaneousPower",
|
||||||
device_class=DEVICE_CLASS_POWER,
|
device_class=DEVICE_CLASS_POWER,
|
||||||
|
@ -29,9 +29,11 @@ from homeassistant.const import (
|
|||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
DEVICE_CLASS_BATTERY,
|
DEVICE_CLASS_BATTERY,
|
||||||
|
DEVICE_CLASS_CURRENT,
|
||||||
DEVICE_CLASS_ENERGY,
|
DEVICE_CLASS_ENERGY,
|
||||||
DEVICE_CLASS_POWER,
|
DEVICE_CLASS_POWER,
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
DEVICE_CLASS_TEMPERATURE,
|
||||||
|
ELECTRIC_CURRENT_AMPERE,
|
||||||
ENERGY_KILO_WATT_HOUR,
|
ENERGY_KILO_WATT_HOUR,
|
||||||
LENGTH_KILOMETERS,
|
LENGTH_KILOMETERS,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
@ -313,10 +315,10 @@ MOCK_VEHICLES = {
|
|||||||
"entity_id": "sensor.charging_power",
|
"entity_id": "sensor.charging_power",
|
||||||
"unique_id": "vf1aaaaa555777999_charging_power",
|
"unique_id": "vf1aaaaa555777999_charging_power",
|
||||||
"result": STATE_UNKNOWN,
|
"result": STATE_UNKNOWN,
|
||||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_POWER,
|
ATTR_DEVICE_CLASS: DEVICE_CLASS_CURRENT,
|
||||||
ATTR_LAST_UPDATE: "2020-11-17T08:06:48+00:00",
|
ATTR_LAST_UPDATE: "2020-11-17T08:06:48+00:00",
|
||||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||||
ATTR_UNIT_OF_MEASUREMENT: POWER_KILO_WATT,
|
ATTR_UNIT_OF_MEASUREMENT: ELECTRIC_CURRENT_AMPERE,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"entity_id": "sensor.charging_remaining_time",
|
"entity_id": "sensor.charging_remaining_time",
|
||||||
@ -450,10 +452,10 @@ MOCK_VEHICLES = {
|
|||||||
"entity_id": "sensor.charging_power",
|
"entity_id": "sensor.charging_power",
|
||||||
"unique_id": "vf1aaaaa555777123_charging_power",
|
"unique_id": "vf1aaaaa555777123_charging_power",
|
||||||
"result": "27.0",
|
"result": "27.0",
|
||||||
ATTR_DEVICE_CLASS: DEVICE_CLASS_POWER,
|
ATTR_DEVICE_CLASS: DEVICE_CLASS_CURRENT,
|
||||||
ATTR_LAST_UPDATE: "2020-01-12T21:40:16+00:00",
|
ATTR_LAST_UPDATE: "2020-01-12T21:40:16+00:00",
|
||||||
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
ATTR_STATE_CLASS: STATE_CLASS_MEASUREMENT,
|
||||||
ATTR_UNIT_OF_MEASUREMENT: POWER_KILO_WATT,
|
ATTR_UNIT_OF_MEASUREMENT: ELECTRIC_CURRENT_AMPERE,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"entity_id": "sensor.charging_remaining_time",
|
"entity_id": "sensor.charging_remaining_time",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user