Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions homeassistant/components/powerwall/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
ATTR_GRID_CODE,
ATTR_NOMINAL_SYSTEM_POWER,
ATTR_REGION,
CHARGING_MARGIN_OF_ERROR,
DOMAIN,
POWERWALL_API_DEVICE_TYPE,
POWERWALL_API_GRID_STATUS,
Expand Down Expand Up @@ -139,7 +138,7 @@ def is_on(self):


class PowerWallChargingStatusSensor(PowerWallEntity, BinarySensorDevice):
"""Representation of an Powerwall grid status sensor."""
"""Representation of an Powerwall charging status sensor."""

@property
def name(self):
Expand All @@ -158,10 +157,8 @@ def unique_id(self):

@property
def is_on(self):
"""Grid is online."""
return (
self._coordinator.data[POWERWALL_API_METERS][
POWERWALL_BATTERY_METER
].instant_power
< CHARGING_MARGIN_OF_ERROR
)
"""Powerwall is charging."""
# is_sending_to returns true for values greater than 100 watts
return self._coordinator.data[POWERWALL_API_METERS][
POWERWALL_BATTERY_METER
].is_sending_to()
10 changes: 3 additions & 7 deletions homeassistant/components/powerwall/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
ATTR_REGION = "region"
ATTR_GRID_CODE = "grid_code"
ATTR_FREQUENCY = "frequency"
ATTR_ENERGY_EXPORTED = "energy_exported"
ATTR_ENERGY_IMPORTED = "energy_imported"
ATTR_ENERGY_EXPORTED = "energy_exported_(in_kW)"
ATTR_ENERGY_IMPORTED = "energy_imported_(in_kW)"
ATTR_INSTANT_AVERAGE_VOLTAGE = "instant_average_voltage"
ATTR_NOMINAL_SYSTEM_POWER = "nominal_system_power_kW"
ATTR_IS_ACTIVE = "is_active"

SITE_INFO_UTILITY = "utility"
SITE_INFO_GRID_CODE = "grid_code"
Expand Down Expand Up @@ -44,11 +45,6 @@

POWERWALL_BATTERY_METER = "battery"

# We only declare charging if they are getting
# at least 40W incoming as measuring the fields
# is not an exact science because of interference
CHARGING_MARGIN_OF_ERROR = -40

MODEL = "PowerWall 2"
MANUFACTURER = "Tesla"

Expand Down
12 changes: 7 additions & 5 deletions homeassistant/components/powerwall/sensor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Support for August sensors."""
import logging

from tesla_powerwall import MeterType
from tesla_powerwall import MeterType, convert_to_kw

from homeassistant.const import (
DEVICE_CLASS_BATTERY,
Expand All @@ -14,6 +14,7 @@
ATTR_ENERGY_IMPORTED,
ATTR_FREQUENCY,
ATTR_INSTANT_AVERAGE_VOLTAGE,
ATTR_IS_ACTIVE,
DOMAIN,
ENERGY_KILO_WATT,
POWERWALL_API_CHARGE,
Expand Down Expand Up @@ -143,8 +144,9 @@ def device_state_attributes(self):
"""Return the device specific state attributes."""
meter = self._coordinator.data[POWERWALL_API_METERS].get(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,
ATTR_FREQUENCY: round(meter.frequency, 1),
ATTR_ENERGY_EXPORTED: convert_to_kw(meter.energy_exported),
ATTR_ENERGY_IMPORTED: convert_to_kw(meter.energy_imported),
ATTR_INSTANT_AVERAGE_VOLTAGE: round(meter.instant_average_voltage, 1),
ATTR_IS_ACTIVE: meter.is_active(),
}
30 changes: 17 additions & 13 deletions tests/components/powerwall/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ async def test_sensors(hass):
assert state.state == "0.032"
expected_attributes = {
"frequency": 60,
"energy_exported": 10429451.9916853,
"energy_imported": 4824191.60668611,
"instant_average_voltage": 120.650001525879,
"energy_exported_(in_kW)": 10429.5,
"energy_imported_(in_kW)": 4824.2,
"instant_average_voltage": 120.7,
"unit_of_measurement": "kW",
"friendly_name": "Powerwall Site Now",
"device_class": "power",
"is_active": False,
}
# Only test for a subset of attributes in case
# HA changes the implementation and a new one appears
Expand All @@ -52,12 +53,13 @@ async def test_sensors(hass):
assert state.state == "1.971"
expected_attributes = {
"frequency": 60,
"energy_exported": 1056797.48917483,
"energy_imported": 4692987.91889705,
"instant_average_voltage": 120.650001525879,
"energy_exported_(in_kW)": 1056.8,
"energy_imported_(in_kW)": 4693.0,
"instant_average_voltage": 120.7,
"unit_of_measurement": "kW",
"friendly_name": "Powerwall Load Now",
"device_class": "power",
"is_active": True,
}
# Only test for a subset of attributes in case
# HA changes the implementation and a new one appears
Expand All @@ -67,13 +69,14 @@ async def test_sensors(hass):
state = hass.states.get("sensor.powerwall_battery_now")
assert state.state == "-8.55"
expected_attributes = {
"frequency": 60.014,
"energy_exported": 3620010,
"energy_imported": 4216170,
"instant_average_voltage": 240.56,
"frequency": 60.0,
"energy_exported_(in_kW)": 3620.0,
"energy_imported_(in_kW)": 4216.2,
"instant_average_voltage": 240.6,
"unit_of_measurement": "kW",
"friendly_name": "Powerwall Battery Now",
"device_class": "power",
"is_active": True,
}
# Only test for a subset of attributes in case
# HA changes the implementation and a new one appears
Expand All @@ -84,12 +87,13 @@ async def test_sensors(hass):
assert state.state == "10.49"
expected_attributes = {
"frequency": 60,
"energy_exported": 9864205.82222448,
"energy_imported": 28177.5358355867,
"instant_average_voltage": 120.685001373291,
"energy_exported_(in_kW)": 9864.2,
"energy_imported_(in_kW)": 28.2,
"instant_average_voltage": 120.7,
"unit_of_measurement": "kW",
"friendly_name": "Powerwall Solar Now",
"device_class": "power",
"is_active": True,
}
# Only test for a subset of attributes in case
# HA changes the implementation and a new one appears
Expand Down