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
2 changes: 1 addition & 1 deletion homeassistant/components/powerwall/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def unique_id(self):

@property
def is_on(self):
"""Get the current value in kWh."""
"""Grid is online."""
return (
self._coordinator.data[POWERWALL_API_GRID_STATUS] == POWERWALL_GRID_ONLINE
)
6 changes: 3 additions & 3 deletions homeassistant/components/powerwall/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

DOMAIN = "powerwall"

POWERWALL_SITE_NAME = "site_name"

POWERWALL_OBJECT = "powerwall"
POWERWALL_COORDINATOR = "coordinator"

UPDATE_INTERVAL = 60
UPDATE_INTERVAL = 30

ATTR_REGION = "region"
ATTR_GRID_CODE = "grid_code"
Expand Down Expand Up @@ -46,3 +44,5 @@

MODEL = "PowerWall 2"
MANUFACTURER = "Tesla"

ENERGY_KILO_WATT = "kW"
6 changes: 3 additions & 3 deletions homeassistant/components/powerwall/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from homeassistant.const import (
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_POWER,
ENERGY_KILO_WATT_HOUR,
UNIT_PERCENTAGE,
)

Expand All @@ -14,6 +13,7 @@
ATTR_FREQUENCY,
ATTR_INSTANT_AVERAGE_VOLTAGE,
DOMAIN,
ENERGY_KILO_WATT,
POWERWALL_API_CHARGE,
POWERWALL_API_DEVICE_TYPE,
POWERWALL_API_METERS,
Expand Down Expand Up @@ -87,7 +87,7 @@ def __init__(self, meter, coordinator, site_info, status, device_type):
@property
def unit_of_measurement(self):
"""Return the unit of measurement."""
return ENERGY_KILO_WATT_HOUR
return ENERGY_KILO_WATT

@property
def name(self):
Expand All @@ -106,7 +106,7 @@ def unique_id(self):

@property
def state(self):
"""Get the current value in kWh."""
"""Get the current value in kW."""
meter = self._coordinator.data[POWERWALL_API_METERS][self._meter]
return round(float(meter.instant_power / 1000), 3)

Expand Down
23 changes: 14 additions & 9 deletions tests/components/powerwall/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ async def test_sensors(hass):
"energy_exported": 10429451.9916853,
"energy_imported": 4824191.60668611,
"instant_average_voltage": 120.650001525879,
"unit_of_measurement": "kWh",
"unit_of_measurement": "kW",
"friendly_name": "Powerwall Site Now",
"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())
for key, value in expected_attributes.items():
assert state.attributes[key] == value

state = hass.states.get("sensor.powerwall_load_now")
assert state.state == "1.971"
Expand All @@ -54,13 +55,14 @@ async def test_sensors(hass):
"energy_exported": 1056797.48917483,
"energy_imported": 4692987.91889705,
"instant_average_voltage": 120.650001525879,
"unit_of_measurement": "kWh",
"unit_of_measurement": "kW",
"friendly_name": "Powerwall Load Now",
"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())
for key, value in expected_attributes.items():
assert state.attributes[key] == value

state = hass.states.get("sensor.powerwall_battery_now")
assert state.state == "-8.55"
Expand All @@ -69,13 +71,14 @@ async def test_sensors(hass):
"energy_exported": 3620010,
"energy_imported": 4216170,
"instant_average_voltage": 240.56,
"unit_of_measurement": "kWh",
"unit_of_measurement": "kW",
"friendly_name": "Powerwall Battery Now",
"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())
for key, value in expected_attributes.items():
assert state.attributes[key] == value

state = hass.states.get("sensor.powerwall_solar_now")
assert state.state == "10.49"
Expand All @@ -84,13 +87,14 @@ async def test_sensors(hass):
"energy_exported": 9864205.82222448,
"energy_imported": 28177.5358355867,
"instant_average_voltage": 120.685001373291,
"unit_of_measurement": "kWh",
"unit_of_measurement": "kW",
"friendly_name": "Powerwall Solar Now",
"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())
for key, value in expected_attributes.items():
assert state.attributes[key] == value

state = hass.states.get("sensor.powerwall_charge")
assert state.state == "47.32"
Expand All @@ -101,4 +105,5 @@ async def test_sensors(hass):
}
# 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())
for key, value in expected_attributes.items():
assert state.attributes[key] == value