mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 10:17:51 +00:00
Fix powerwall units (kW) (#33954)
* Fix powerwall units (kW) * Fix test Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
7b9585cd8e
commit
ca0648afe8
@ -129,7 +129,7 @@ class PowerWallGridStatusSensor(PowerWallEntity, BinarySensorDevice):
|
||||
|
||||
@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
|
||||
)
|
||||
|
@ -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"
|
||||
@ -46,3 +44,5 @@ POWERWALL_RUNNING_KEY = "running"
|
||||
|
||||
MODEL = "PowerWall 2"
|
||||
MANUFACTURER = "Tesla"
|
||||
|
||||
ENERGY_KILO_WATT = "kW"
|
||||
|
@ -4,7 +4,6 @@ import logging
|
||||
from homeassistant.const import (
|
||||
DEVICE_CLASS_BATTERY,
|
||||
DEVICE_CLASS_POWER,
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
UNIT_PERCENTAGE,
|
||||
)
|
||||
|
||||
@ -14,6 +13,7 @@ from .const import (
|
||||
ATTR_FREQUENCY,
|
||||
ATTR_INSTANT_AVERAGE_VOLTAGE,
|
||||
DOMAIN,
|
||||
ENERGY_KILO_WATT,
|
||||
POWERWALL_API_CHARGE,
|
||||
POWERWALL_API_DEVICE_TYPE,
|
||||
POWERWALL_API_METERS,
|
||||
@ -87,7 +87,7 @@ class PowerWallEnergySensor(PowerWallEntity):
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return ENERGY_KILO_WATT_HOUR
|
||||
return ENERGY_KILO_WATT
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
@ -106,7 +106,7 @@ class PowerWallEnergySensor(PowerWallEntity):
|
||||
|
||||
@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)
|
||||
|
||||
|
@ -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"
|
||||
@ -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"
|
||||
@ -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"
|
||||
@ -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"
|
||||
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user