Skip to content

Commit

Permalink
Add Grid status
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Oct 10, 2024
1 parent 6363414 commit 1d74312
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions custom_components/teslemetry/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,14 @@ async def async_setup_entry(
for energysite in entry.runtime_data.energysites
for description in ENERGY_LIVE_DESCRIPTIONS
if energysite.info_coordinator.data.get("components_battery")
if description.key in energysite.live_coordinator.data
),
( # Energy Site Info
TeslemetryEnergyInfoBinarySensorEntity(energysite, description)
for energysite in entry.runtime_data.energysites
for description in ENERGY_INFO_DESCRIPTIONS
if energysite.info_coordinator.data.get("components_battery")
if description.key in energysite.info_coordinator.data
),
)
)
Expand Down
4 changes: 4 additions & 0 deletions custom_components/teslemetry/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,9 @@ class TeslemetryEnergySensorEntityDescription(SensorEntityDescription):
value_fn: Callable[[StateType], StateType | datetime] = lambda x: x

ENERGY_LIVE_DESCRIPTIONS: tuple[TeslemetryEnergySensorEntityDescription, ...] = (
TeslemetryEnergySensorEntityDescription(
key="grid_status",
),
TeslemetryEnergySensorEntityDescription(
key="solar_power",
state_class=SensorStateClass.MEASUREMENT,
Expand Down Expand Up @@ -1060,6 +1063,7 @@ class TeslemetryEnergySensorEntityDescription(SensorEntityDescription):
device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
suggested_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
suggested_display_precision=2,
state_class=SensorStateClass.TOTAL_INCREASING,
entity_registry_enabled_default=(key.startswith("total") or key=="grid_energy_imported"),
value_fn=lambda x: x.get(key, 0),
Expand Down
5 changes: 4 additions & 1 deletion custom_components/teslemetry/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,9 @@
"off_grid_unintentional": "Off grid unintentional"
}
},
"grid_status": {
"name": "Grid status"
},
"load_power": {
"name": "Load power"
},
Expand Down Expand Up @@ -1161,4 +1164,4 @@
"name": "Set valet mode"
}
}
}
}

0 comments on commit 1d74312

Please sign in to comment.