Include charging state for powerwall (#33432)

* Switch to binary sensor for charging status per review

* Powerwall charging margin of error is much higher than expected
This commit is contained in:
J. Nick Koston authored and GitHub committed 2020-04-19 20:50:42 -05:00
1 parent 675525f47c
commit 75e5f085d3
3 files changed
+51 -1

No files matched your search

@@ -1,9 +1,10 @@
"""Support for August sensors."""
"""Support for powerwall binary sensors."""
import logging
from tesla_powerwall import GridStatus
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_BATTERY_CHARGING,
DEVICE_CLASS_CONNECTIVITY,
BinarySensorDevice,
)
@@ -13,13 +14,16 @@ from .const import (
ATTR_GRID_CODE,
ATTR_NOMINAL_SYSTEM_POWER,
ATTR_REGION,
CHARGING_MARGIN_OF_ERROR,
DOMAIN,
POWERWALL_API_DEVICE_TYPE,
POWERWALL_API_GRID_STATUS,
POWERWALL_API_METERS,
POWERWALL_API_SERIAL_NUMBERS,
POWERWALL_API_SITE_INFO,
POWERWALL_API_SITEMASTER,
POWERWALL_API_STATUS,
POWERWALL_BATTERY_METER,
POWERWALL_COORDINATOR,
)
from .entity import PowerWallEntity
@@ -42,6 +46,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
PowerWallRunningSensor,
PowerWallGridStatusSensor,
PowerWallConnectedSensor,
PowerWallChargingStatusSensor,
):
entities.append(
sensor_class(
@@ -131,3 +136,32 @@ class PowerWallGridStatusSensor(PowerWallEntity, BinarySensorDevice):
def is_on(self):
"""Grid is online."""
return self._coordinator.data[POWERWALL_API_GRID_STATUS] == GridStatus.CONNECTED
class PowerWallChargingStatusSensor(PowerWallEntity, BinarySensorDevice):
"""Representation of an Powerwall grid status sensor."""
@property
def name(self):
"""Device Name."""
return "Powerwall Charging"
@property
def device_class(self):
"""Device Class."""
return DEVICE_CLASS_BATTERY_CHARGING
@property
def unique_id(self):
"""Device Uniqueid."""
return f"{self.base_unique_id}_powerwall_charging"
@property
def is_on(self):
"""Grid is online."""
return (
self._coordinator.data[POWERWALL_API_METERS][
POWERWALL_BATTERY_METER
].instant_power
< CHARGING_MARGIN_OF_ERROR
)