mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Add grid services active sensor to telsa powerwall integration (#56317)
Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
parent
1b42caa34a
commit
b2d67f8d19
@ -23,6 +23,7 @@ from .const import (
|
||||
POWERWALL_API_CHANGED,
|
||||
POWERWALL_API_CHARGE,
|
||||
POWERWALL_API_DEVICE_TYPE,
|
||||
POWERWALL_API_GRID_SERVICES_ACTIVE,
|
||||
POWERWALL_API_GRID_STATUS,
|
||||
POWERWALL_API_METERS,
|
||||
POWERWALL_API_SERIAL_NUMBERS,
|
||||
@ -225,6 +226,7 @@ def _fetch_powerwall_data(power_wall):
|
||||
POWERWALL_API_CHARGE: power_wall.get_charge(),
|
||||
POWERWALL_API_SITEMASTER: power_wall.get_sitemaster(),
|
||||
POWERWALL_API_METERS: power_wall.get_meters(),
|
||||
POWERWALL_API_GRID_SERVICES_ACTIVE: power_wall.is_grid_services_active(),
|
||||
POWERWALL_API_GRID_STATUS: power_wall.get_grid_status(),
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ from homeassistant.const import DEVICE_CLASS_POWER
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
POWERWALL_API_DEVICE_TYPE,
|
||||
POWERWALL_API_GRID_SERVICES_ACTIVE,
|
||||
POWERWALL_API_GRID_STATUS,
|
||||
POWERWALL_API_METERS,
|
||||
POWERWALL_API_SERIAL_NUMBERS,
|
||||
@ -35,6 +36,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
entities = []
|
||||
for sensor_class in (
|
||||
PowerWallRunningSensor,
|
||||
PowerWallGridServicesActiveSensor,
|
||||
PowerWallGridStatusSensor,
|
||||
PowerWallConnectedSensor,
|
||||
PowerWallChargingStatusSensor,
|
||||
@ -96,6 +98,30 @@ class PowerWallConnectedSensor(PowerWallEntity, BinarySensorEntity):
|
||||
return self.coordinator.data[POWERWALL_API_SITEMASTER].is_connected_to_tesla
|
||||
|
||||
|
||||
class PowerWallGridServicesActiveSensor(PowerWallEntity, BinarySensorEntity):
|
||||
"""Representation of a Powerwall grid services active sensor."""
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Device Name."""
|
||||
return "Grid Services Active"
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Device Class."""
|
||||
return DEVICE_CLASS_POWER
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Device Uniqueid."""
|
||||
return f"{self.base_unique_id}_grid_services_active"
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Grid services is active."""
|
||||
return self.coordinator.data[POWERWALL_API_GRID_SERVICES_ACTIVE]
|
||||
|
||||
|
||||
class PowerWallGridStatusSensor(PowerWallEntity, BinarySensorEntity):
|
||||
"""Representation of an Powerwall grid status sensor."""
|
||||
|
||||
|
@ -19,6 +19,7 @@ POWERWALL_SITE_NAME = "site_name"
|
||||
|
||||
POWERWALL_API_METERS = "meters"
|
||||
POWERWALL_API_CHARGE = "charge"
|
||||
POWERWALL_API_GRID_SERVICES_ACTIVE = "grid_services_active"
|
||||
POWERWALL_API_GRID_STATUS = "grid_status"
|
||||
POWERWALL_API_SITEMASTER = "sitemaster"
|
||||
POWERWALL_API_STATUS = "status"
|
||||
|
@ -30,6 +30,7 @@ async def _mock_powerwall_with_fixtures(hass):
|
||||
charge=47.34587394586,
|
||||
sitemaster=SiteMaster(sitemaster),
|
||||
meters=MetersAggregates(meters),
|
||||
grid_services_active=True,
|
||||
grid_status=GridStatus.CONNECTED,
|
||||
status=PowerwallStatus(status),
|
||||
device_type=DeviceType(device_type["device_type"]),
|
||||
@ -42,6 +43,7 @@ def _mock_powerwall_return_value(
|
||||
charge=None,
|
||||
sitemaster=None,
|
||||
meters=None,
|
||||
grid_services_active=None,
|
||||
grid_status=None,
|
||||
status=None,
|
||||
device_type=None,
|
||||
@ -56,6 +58,7 @@ def _mock_powerwall_return_value(
|
||||
powerwall_mock.get_status = Mock(return_value=status)
|
||||
powerwall_mock.get_device_type = Mock(return_value=device_type)
|
||||
powerwall_mock.get_serial_numbers = Mock(return_value=serial_numbers)
|
||||
powerwall_mock.is_grid_services_active = Mock(return_value=grid_services_active)
|
||||
|
||||
return powerwall_mock
|
||||
|
||||
|
@ -26,6 +26,16 @@ async def test_sensors(hass):
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("binary_sensor.grid_services_active")
|
||||
assert state.state == STATE_ON
|
||||
expected_attributes = {
|
||||
"friendly_name": "Grid Services Active",
|
||||
"device_class": "power",
|
||||
}
|
||||
# Only test for a subset of attributes in case
|
||||
# HA changes the implementation and a new one appears
|
||||
assert all(item in state.attributes.items() for item in expected_attributes.items())
|
||||
|
||||
state = hass.states.get("binary_sensor.grid_status")
|
||||
assert state.state == STATE_ON
|
||||
expected_attributes = {"friendly_name": "Grid Status", "device_class": "power"}
|
||||
|
Loading…
x
Reference in New Issue
Block a user