Add Powerwalls integration (#32851)
* Create an integration for Powerwalls * Self review :: remove unused code * Remove debug * Update homeassistant/components/powerwall/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * _call_site_info to module level * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update tests/components/powerwall/test_binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/binary_sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * remove sensors that I added tests for from the comment * Update homeassistant/components/powerwall/config_flow.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/powerwall/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Switch to UNIT_PERCENTAGE * reduce code * Add test for import * Adjust tests * Add missing file Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
1 parent
242aff9269
commit
5b4d2aed64
20 files changed
+990
No files matched your search
@@ -0,0 +1,130 @@
|
||||
"""The Tesla Powerwall integration."""
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
from tesla_powerwall import (
|
||||
ApiError,
|
||||
MetersResponse,
|
||||
PowerWall,
|
||||
PowerWallUnreachableError,
|
||||
)
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.const import CONF_IP_ADDRESS
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
POWERWALL_API_CHARGE,
|
||||
POWERWALL_API_GRID_STATUS,
|
||||
POWERWALL_API_METERS,
|
||||
POWERWALL_API_SITEMASTER,
|
||||
POWERWALL_COORDINATOR,
|
||||
POWERWALL_OBJECT,
|
||||
POWERWALL_SITE_INFO,
|
||||
UPDATE_INTERVAL,
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{DOMAIN: vol.Schema({vol.Required(CONF_IP_ADDRESS): cv.string})},
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
)
|
||||
|
||||
PLATFORMS = ["binary_sensor", "sensor"]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: dict):
|
||||
"""Set up the Tesla Powerwall component."""
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
conf = config.get(DOMAIN)
|
||||
|
||||
if not conf:
|
||||
return True
|
||||
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=conf,
|
||||
)
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||
"""Set up Tesla Powerwall from a config entry."""
|
||||
|
||||
entry_id = entry.entry_id
|
||||
|
||||
hass.data[DOMAIN].setdefault(entry_id, {})
|
||||
power_wall = PowerWall(entry.data[CONF_IP_ADDRESS])
|
||||
try:
|
||||
site_info = await hass.async_add_executor_job(call_site_info, power_wall)
|
||||
except (PowerWallUnreachableError, ApiError, ConnectionError):
|
||||
raise ConfigEntryNotReady
|
||||
|
||||
async def async_update_data():
|
||||
"""Fetch data from API endpoint."""
|
||||
return await hass.async_add_executor_job(_fetch_powerwall_data, power_wall)
|
||||
|
||||
coordinator = DataUpdateCoordinator(
|
||||
hass,
|
||||
_LOGGER,
|
||||
name="Powerwall site",
|
||||
update_method=async_update_data,
|
||||
update_interval=timedelta(seconds=UPDATE_INTERVAL),
|
||||
)
|
||||
|
||||
hass.data[DOMAIN][entry.entry_id] = {
|
||||
POWERWALL_OBJECT: power_wall,
|
||||
POWERWALL_COORDINATOR: coordinator,
|
||||
POWERWALL_SITE_INFO: site_info,
|
||||
}
|
||||
|
||||
await coordinator.async_refresh()
|
||||
|
||||
for component in PLATFORMS:
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(entry, component)
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def call_site_info(power_wall):
|
||||
"""Wrap site_info to be a callable."""
|
||||
return power_wall.site_info
|
||||
|
||||
|
||||
def _fetch_powerwall_data(power_wall):
|
||||
"""Process and update powerwall data."""
|
||||
meters = power_wall.meters
|
||||
return {
|
||||
POWERWALL_API_CHARGE: power_wall.charge,
|
||||
POWERWALL_API_SITEMASTER: power_wall.sitemaster,
|
||||
POWERWALL_API_METERS: {
|
||||
meter: MetersResponse(meters[meter]) for meter in meters
|
||||
},
|
||||
POWERWALL_API_GRID_STATUS: power_wall.grid_status,
|
||||
}
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
||||
"""Unload a config entry."""
|
||||
unload_ok = all(
|
||||
await asyncio.gather(
|
||||
*[
|
||||
hass.config_entries.async_forward_entry_unload(entry, component)
|
||||
for component in PLATFORMS
|
||||
]
|
||||
)
|
||||
)
|
||||
if unload_ok:
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
|
||||
return unload_ok
|
||||
@@ -0,0 +1,131 @@
|
||||
"""Support for August sensors."""
|
||||
import logging
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
DEVICE_CLASS_CONNECTIVITY,
|
||||
BinarySensorDevice,
|
||||
)
|
||||
from homeassistant.const import DEVICE_CLASS_POWER
|
||||
|
||||
from .const import (
|
||||
ATTR_GRID_CODE,
|
||||
ATTR_NOMINAL_SYSTEM_POWER,
|
||||
ATTR_REGION,
|
||||
DOMAIN,
|
||||
POWERWALL_API_GRID_STATUS,
|
||||
POWERWALL_API_SITEMASTER,
|
||||
POWERWALL_CONNECTED_KEY,
|
||||
POWERWALL_COORDINATOR,
|
||||
POWERWALL_GRID_ONLINE,
|
||||
POWERWALL_RUNNING_KEY,
|
||||
POWERWALL_SITE_INFO,
|
||||
SITE_INFO_GRID_CODE,
|
||||
SITE_INFO_NOMINAL_SYSTEM_POWER_KW,
|
||||
SITE_INFO_REGION,
|
||||
)
|
||||
from .entity import PowerWallEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up the August sensors."""
|
||||
powerwall_data = hass.data[DOMAIN][config_entry.entry_id]
|
||||
|
||||
coordinator = powerwall_data[POWERWALL_COORDINATOR]
|
||||
site_info = powerwall_data[POWERWALL_SITE_INFO]
|
||||
|
||||
entities = []
|
||||
for sensor_class in (
|
||||
PowerWallRunningSensor,
|
||||
PowerWallGridStatusSensor,
|
||||
PowerWallConnectedSensor,
|
||||
):
|
||||
entities.append(sensor_class(coordinator, site_info))
|
||||
|
||||
async_add_entities(entities, True)
|
||||
|
||||
|
||||
class PowerWallRunningSensor(PowerWallEntity, BinarySensorDevice):
|
||||
"""Representation of an Powerwall running sensor."""
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Device Name."""
|
||||
return "Powerwall Status"
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Device Class."""
|
||||
return DEVICE_CLASS_POWER
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Device Uniqueid."""
|
||||
return f"{self.base_unique_id}_running"
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Get the powerwall running state."""
|
||||
return self._coordinator.data[POWERWALL_API_SITEMASTER][POWERWALL_RUNNING_KEY]
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the device specific state attributes."""
|
||||
return {
|
||||
ATTR_REGION: self._site_info[SITE_INFO_REGION],
|
||||
ATTR_GRID_CODE: self._site_info[SITE_INFO_GRID_CODE],
|
||||
ATTR_NOMINAL_SYSTEM_POWER: self._site_info[
|
||||
SITE_INFO_NOMINAL_SYSTEM_POWER_KW
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
class PowerWallConnectedSensor(PowerWallEntity, BinarySensorDevice):
|
||||
"""Representation of an Powerwall connected sensor."""
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Device Name."""
|
||||
return "Powerwall Connected to Tesla"
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Device Class."""
|
||||
return DEVICE_CLASS_CONNECTIVITY
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Device Uniqueid."""
|
||||
return f"{self.base_unique_id}_connected_to_tesla"
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Get the powerwall connected to tesla state."""
|
||||
return self._coordinator.data[POWERWALL_API_SITEMASTER][POWERWALL_CONNECTED_KEY]
|
||||
|
||||
|
||||
class PowerWallGridStatusSensor(PowerWallEntity, BinarySensorDevice):
|
||||
"""Representation of an Powerwall grid status sensor."""
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Device Name."""
|
||||
return "Grid Status"
|
||||
|
||||
@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_status"
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Get the current value in kWh."""
|
||||
return (
|
||||
self._coordinator.data[POWERWALL_API_GRID_STATUS] == POWERWALL_GRID_ONLINE
|
||||
)
|
||||
@@ -0,0 +1,72 @@
|
||||
"""Config flow for Tesla Powerwall integration."""
|
||||
import logging
|
||||
|
||||
from tesla_powerwall import ApiError, PowerWall, PowerWallUnreachableError
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries, core, exceptions
|
||||
from homeassistant.const import CONF_IP_ADDRESS
|
||||
|
||||
from . import call_site_info
|
||||
from .const import DOMAIN # pylint:disable=unused-import
|
||||
from .const import POWERWALL_SITE_NAME
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DATA_SCHEMA = vol.Schema({vol.Required(CONF_IP_ADDRESS): str})
|
||||
|
||||
|
||||
async def validate_input(hass: core.HomeAssistant, data):
|
||||
"""Validate the user input allows us to connect.
|
||||
|
||||
Data has the keys from DATA_SCHEMA with values provided by the user.
|
||||
"""
|
||||
|
||||
power_wall = PowerWall(data[CONF_IP_ADDRESS])
|
||||
|
||||
try:
|
||||
site_info = await hass.async_add_executor_job(call_site_info, power_wall)
|
||||
except (PowerWallUnreachableError, ApiError, ConnectionError):
|
||||
raise CannotConnect
|
||||
|
||||
# Return info that you want to store in the config entry.
|
||||
return {"title": site_info[POWERWALL_SITE_NAME]}
|
||||
|
||||
|
||||
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a config flow for Tesla Powerwall."""
|
||||
|
||||
VERSION = 1
|
||||
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
"""Handle the initial step."""
|
||||
errors = {}
|
||||
if user_input is not None:
|
||||
try:
|
||||
info = await validate_input(self.hass, user_input)
|
||||
except CannotConnect:
|
||||
errors["base"] = "cannot_connect"
|
||||
except Exception: # pylint: disable=broad-except
|
||||
_LOGGER.exception("Unexpected exception")
|
||||
errors["base"] = "unknown"
|
||||
|
||||
if "base" not in errors:
|
||||
await self.async_set_unique_id(user_input[CONF_IP_ADDRESS])
|
||||
self._abort_if_unique_id_configured()
|
||||
return self.async_create_entry(title=info["title"], data=user_input)
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="user", data_schema=DATA_SCHEMA, errors=errors
|
||||
)
|
||||
|
||||
async def async_step_import(self, user_input):
|
||||
"""Handle import."""
|
||||
await self.async_set_unique_id(user_input[CONF_IP_ADDRESS])
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
return await self.async_step_user(user_input)
|
||||
|
||||
|
||||
class CannotConnect(exceptions.HomeAssistantError):
|
||||
"""Error to indicate we cannot connect."""
|
||||
@@ -0,0 +1,40 @@
|
||||
"""Constants for the Tesla Powerwall integration."""
|
||||
|
||||
DOMAIN = "powerwall"
|
||||
|
||||
POWERWALL_SITE_NAME = "site_name"
|
||||
|
||||
POWERWALL_OBJECT = "powerwall"
|
||||
POWERWALL_COORDINATOR = "coordinator"
|
||||
POWERWALL_SITE_INFO = "site_info"
|
||||
|
||||
UPDATE_INTERVAL = 60
|
||||
|
||||
ATTR_REGION = "region"
|
||||
ATTR_GRID_CODE = "grid_code"
|
||||
ATTR_FREQUENCY = "frequency"
|
||||
ATTR_ENERGY_EXPORTED = "energy_exported"
|
||||
ATTR_ENERGY_IMPORTED = "energy_imported"
|
||||
ATTR_INSTANT_AVERAGE_VOLTAGE = "instant_average_voltage"
|
||||
ATTR_NOMINAL_SYSTEM_POWER = "nominal_system_power_kW"
|
||||
|
||||
SITE_INFO_UTILITY = "utility"
|
||||
SITE_INFO_GRID_CODE = "grid_code"
|
||||
SITE_INFO_NOMINAL_SYSTEM_POWER_KW = "nominal_system_power_kW"
|
||||
SITE_INFO_NOMINAL_SYSTEM_ENERGY_KWH = "nominal_system_energy_kWh"
|
||||
SITE_INFO_REGION = "region"
|
||||
|
||||
POWERWALL_SITE_NAME = "site_name"
|
||||
|
||||
POWERWALL_API_METERS = "meters"
|
||||
POWERWALL_API_CHARGE = "charge"
|
||||
POWERWALL_API_GRID_STATUS = "grid_status"
|
||||
POWERWALL_API_SITEMASTER = "sitemaster"
|
||||
|
||||
POWERWALL_GRID_ONLINE = "SystemGridConnected"
|
||||
POWERWALL_CONNECTED_KEY = "connected_to_tesla"
|
||||
POWERWALL_RUNNING_KEY = "running"
|
||||
|
||||
|
||||
MODEL = "PowerWall 2"
|
||||
MANUFACTURER = "Tesla"
|
||||
@@ -0,0 +1,67 @@
|
||||
"""The Tesla Powerwall integration base entity."""
|
||||
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
MANUFACTURER,
|
||||
MODEL,
|
||||
POWERWALL_SITE_NAME,
|
||||
SITE_INFO_GRID_CODE,
|
||||
SITE_INFO_NOMINAL_SYSTEM_ENERGY_KWH,
|
||||
SITE_INFO_NOMINAL_SYSTEM_POWER_KW,
|
||||
SITE_INFO_UTILITY,
|
||||
)
|
||||
|
||||
|
||||
class PowerWallEntity(Entity):
|
||||
"""Base class for powerwall entities."""
|
||||
|
||||
def __init__(self, coordinator, site_info):
|
||||
"""Initialize the sensor."""
|
||||
super().__init__()
|
||||
self._coordinator = coordinator
|
||||
self._site_info = site_info
|
||||
# This group of properties will be unique to to the site
|
||||
unique_group = (
|
||||
site_info[SITE_INFO_UTILITY],
|
||||
site_info[SITE_INFO_GRID_CODE],
|
||||
str(site_info[SITE_INFO_NOMINAL_SYSTEM_POWER_KW]),
|
||||
str(site_info[SITE_INFO_NOMINAL_SYSTEM_ENERGY_KWH]),
|
||||
)
|
||||
self.base_unique_id = "_".join(unique_group)
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
"""Powerwall device info."""
|
||||
return {
|
||||
"identifiers": {(DOMAIN, self.base_unique_id)},
|
||||
"name": self._site_info[POWERWALL_SITE_NAME],
|
||||
"manufacturer": MANUFACTURER,
|
||||
"model": MODEL,
|
||||
}
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Return True if entity is available."""
|
||||
return self._coordinator.last_update_success
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return False, updates are controlled via coordinator."""
|
||||
return False
|
||||
|
||||
async def async_update(self):
|
||||
"""Update the entity.
|
||||
|
||||
Only used by the generic entity update service.
|
||||
"""
|
||||
await self._coordinator.async_request_refresh()
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe to updates."""
|
||||
self._coordinator.async_add_listener(self.async_write_ha_state)
|
||||
|
||||
async def async_will_remove_from_hass(self):
|
||||
"""Undo subscription."""
|
||||
self._coordinator.async_remove_listener(self.async_write_ha_state)
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"domain": "powerwall",
|
||||
"name": "Tesla Powerwall",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/powerwall",
|
||||
"requirements": [
|
||||
"tesla-powerwall==0.1.1"
|
||||
],
|
||||
"ssdp": [],
|
||||
"zeroconf": [],
|
||||
"homekit": {},
|
||||
"dependencies": [],
|
||||
"codeowners": [
|
||||
"@bdraco"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
"""Support for August sensors."""
|
||||
import logging
|
||||
|
||||
from homeassistant.const import (
|
||||
DEVICE_CLASS_BATTERY,
|
||||
DEVICE_CLASS_POWER,
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
UNIT_PERCENTAGE,
|
||||
)
|
||||
|
||||
from .const import (
|
||||
ATTR_ENERGY_EXPORTED,
|
||||
ATTR_ENERGY_IMPORTED,
|
||||
ATTR_FREQUENCY,
|
||||
ATTR_INSTANT_AVERAGE_VOLTAGE,
|
||||
DOMAIN,
|
||||
POWERWALL_API_CHARGE,
|
||||
POWERWALL_API_METERS,
|
||||
POWERWALL_COORDINATOR,
|
||||
POWERWALL_SITE_INFO,
|
||||
)
|
||||
from .entity import PowerWallEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up the August sensors."""
|
||||
powerwall_data = hass.data[DOMAIN][config_entry.entry_id]
|
||||
_LOGGER.debug("Powerwall_data: %s", powerwall_data)
|
||||
|
||||
coordinator = powerwall_data[POWERWALL_COORDINATOR]
|
||||
site_info = powerwall_data[POWERWALL_SITE_INFO]
|
||||
|
||||
entities = []
|
||||
for meter in coordinator.data[POWERWALL_API_METERS]:
|
||||
entities.append(PowerWallEnergySensor(meter, coordinator, site_info))
|
||||
|
||||
entities.append(PowerWallChargeSensor(coordinator, site_info))
|
||||
|
||||
async_add_entities(entities, True)
|
||||
|
||||
|
||||
class PowerWallChargeSensor(PowerWallEntity):
|
||||
"""Representation of an Powerwall charge sensor."""
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return UNIT_PERCENTAGE
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Device Name."""
|
||||
return "Powerwall Charge"
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Device Class."""
|
||||
return DEVICE_CLASS_BATTERY
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Device Uniqueid."""
|
||||
return f"{self.base_unique_id}_charge"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Get the current value in percentage."""
|
||||
return round(self._coordinator.data[POWERWALL_API_CHARGE], 3)
|
||||
|
||||
|
||||
class PowerWallEnergySensor(PowerWallEntity):
|
||||
"""Representation of an Powerwall Energy sensor."""
|
||||
|
||||
def __init__(self, meter, coordinator, site_info):
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(coordinator, site_info)
|
||||
self._meter = meter
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return ENERGY_KILO_WATT_HOUR
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Device Name."""
|
||||
return f"Powerwall {self._meter.title()} Now"
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Device Class."""
|
||||
return DEVICE_CLASS_POWER
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Device Uniqueid."""
|
||||
return f"{self.base_unique_id}_{self._meter}_instant_power"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Get the current value in kWh."""
|
||||
meter = self._coordinator.data[POWERWALL_API_METERS][self._meter]
|
||||
return round(float(meter.instant_power / 1000), 3)
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the device specific state attributes."""
|
||||
meter = self._coordinator.data[POWERWALL_API_METERS][self._meter]
|
||||
return {
|
||||
ATTR_FREQUENCY: meter.frequency,
|
||||
ATTR_ENERGY_EXPORTED: meter.energy_exported,
|
||||
ATTR_ENERGY_IMPORTED: meter.energy_imported,
|
||||
ATTR_INSTANT_AVERAGE_VOLTAGE: meter.instant_average_voltage,
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"config": {
|
||||
"title": "Tesla Powerwall",
|
||||
"step": {
|
||||
"user": {
|
||||
"title": "Connect to the powerwall",
|
||||
"data": {
|
||||
"ip_address": "IP Address"
|
||||
}
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
"cannot_connect": "Failed to connect, please try again",
|
||||
"unknown": "Unexpected error"
|
||||
},
|
||||
"abort": {
|
||||
"already_configured": "The powerwall is already configured"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user