mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Fix wall connector state in Teslemetry (#124149)
* Fix wall connector state * review feedback * Rename None to Disconnected * Translate disconnected
This commit is contained in:
parent
bc3a42c658
commit
d90cdf24f5
@ -192,3 +192,10 @@ class TeslemetryWallConnectorEntity(
|
|||||||
.get(self.din, {})
|
.get(self.din, {})
|
||||||
.get(self.key)
|
.get(self.key)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def exists(self) -> bool:
|
||||||
|
"""Return True if it exists in the wall connector coordinator data."""
|
||||||
|
return self.key in self.coordinator.data.get("wall_connectors", {}).get(
|
||||||
|
self.din, {}
|
||||||
|
)
|
||||||
|
@ -379,18 +379,18 @@ ENERGY_LIVE_DESCRIPTIONS: tuple[SensorEntityDescription, ...] = (
|
|||||||
SensorEntityDescription(key="island_status", device_class=SensorDeviceClass.ENUM),
|
SensorEntityDescription(key="island_status", device_class=SensorDeviceClass.ENUM),
|
||||||
)
|
)
|
||||||
|
|
||||||
WALL_CONNECTOR_DESCRIPTIONS: tuple[SensorEntityDescription, ...] = (
|
WALL_CONNECTOR_DESCRIPTIONS: tuple[TeslemetrySensorEntityDescription, ...] = (
|
||||||
SensorEntityDescription(
|
TeslemetrySensorEntityDescription(
|
||||||
key="wall_connector_state",
|
key="wall_connector_state",
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
TeslemetrySensorEntityDescription(
|
||||||
key="wall_connector_fault_state",
|
key="wall_connector_fault_state",
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
entity_registry_enabled_default=False,
|
entity_registry_enabled_default=False,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
TeslemetrySensorEntityDescription(
|
||||||
key="wall_connector_power",
|
key="wall_connector_power",
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
native_unit_of_measurement=UnitOfPower.WATT,
|
native_unit_of_measurement=UnitOfPower.WATT,
|
||||||
@ -398,8 +398,9 @@ WALL_CONNECTOR_DESCRIPTIONS: tuple[SensorEntityDescription, ...] = (
|
|||||||
suggested_display_precision=2,
|
suggested_display_precision=2,
|
||||||
device_class=SensorDeviceClass.POWER,
|
device_class=SensorDeviceClass.POWER,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
TeslemetrySensorEntityDescription(
|
||||||
key="vin",
|
key="vin",
|
||||||
|
value_fn=lambda vin: vin or "disconnected",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -525,13 +526,13 @@ class TeslemetryEnergyLiveSensorEntity(TeslemetryEnergyLiveEntity, SensorEntity)
|
|||||||
class TeslemetryWallConnectorSensorEntity(TeslemetryWallConnectorEntity, SensorEntity):
|
class TeslemetryWallConnectorSensorEntity(TeslemetryWallConnectorEntity, SensorEntity):
|
||||||
"""Base class for Teslemetry energy site metric sensors."""
|
"""Base class for Teslemetry energy site metric sensors."""
|
||||||
|
|
||||||
entity_description: SensorEntityDescription
|
entity_description: TeslemetrySensorEntityDescription
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
data: TeslemetryEnergyData,
|
data: TeslemetryEnergyData,
|
||||||
din: str,
|
din: str,
|
||||||
description: SensorEntityDescription,
|
description: TeslemetrySensorEntityDescription,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
@ -543,8 +544,8 @@ class TeslemetryWallConnectorSensorEntity(TeslemetryWallConnectorEntity, SensorE
|
|||||||
|
|
||||||
def _async_update_attrs(self) -> None:
|
def _async_update_attrs(self) -> None:
|
||||||
"""Update the attributes of the sensor."""
|
"""Update the attributes of the sensor."""
|
||||||
self._attr_available = not self.is_none
|
if self.exists:
|
||||||
self._attr_native_value = self._value
|
self._attr_native_value = self.entity_description.value_fn(self._value)
|
||||||
|
|
||||||
|
|
||||||
class TeslemetryEnergyInfoSensorEntity(TeslemetryEnergyInfoEntity, SensorEntity):
|
class TeslemetryEnergyInfoSensorEntity(TeslemetryEnergyInfoEntity, SensorEntity):
|
||||||
|
@ -420,7 +420,10 @@
|
|||||||
"name": "version"
|
"name": "version"
|
||||||
},
|
},
|
||||||
"vin": {
|
"vin": {
|
||||||
"name": "Vehicle"
|
"name": "Vehicle",
|
||||||
|
"state": {
|
||||||
|
"disconnected": "Disconnected"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"vpp_backup_reserve_percent": {
|
"vpp_backup_reserve_percent": {
|
||||||
"name": "VPP backup reserve"
|
"name": "VPP backup reserve"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user