2020-03-19 10:50:17 -05:00
|
|
|
"""The sensor tests for the powerwall platform."""
|
|
|
|
|
|
|
|
from asynctest import patch
|
|
|
|
|
|
|
|
from homeassistant.components.powerwall.const import DOMAIN
|
2020-04-11 22:53:48 +02:00
|
|
|
from homeassistant.const import UNIT_PERCENTAGE
|
2020-03-19 10:50:17 -05:00
|
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
|
|
|
|
from .mocks import _mock_get_config, _mock_powerwall_with_fixtures
|
|
|
|
|
|
|
|
|
|
|
|
async def test_sensors(hass):
|
|
|
|
"""Test creation of the sensors."""
|
|
|
|
|
|
|
|
mock_powerwall = await _mock_powerwall_with_fixtures(hass)
|
|
|
|
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.powerwall.config_flow.PowerWall",
|
|
|
|
return_value=mock_powerwall,
|
|
|
|
), patch(
|
2020-04-11 22:53:48 +02:00
|
|
|
"homeassistant.components.powerwall.PowerWall", return_value=mock_powerwall
|
2020-03-19 10:50:17 -05:00
|
|
|
):
|
|
|
|
assert await async_setup_component(hass, DOMAIN, _mock_get_config())
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
device_registry = await hass.helpers.device_registry.async_get_registry()
|
|
|
|
reg_device = device_registry.async_get_device(
|
2020-03-19 22:43:09 -05:00
|
|
|
identifiers={("powerwall", "Wom Energy_60Hz_240V_s_IEEE1547a_2014_13.5")},
|
2020-03-19 10:50:17 -05:00
|
|
|
connections=set(),
|
|
|
|
)
|
2020-03-31 14:55:50 -05:00
|
|
|
assert reg_device.model == "PowerWall 2 (hec)"
|
|
|
|
assert reg_device.sw_version == "1.45.1"
|
2020-03-19 10:50:17 -05:00
|
|
|
assert reg_device.manufacturer == "Tesla"
|
|
|
|
assert reg_device.name == "MySite"
|
|
|
|
|
|
|
|
state = hass.states.get("sensor.powerwall_site_now")
|
|
|
|
assert state.state == "0.032"
|
|
|
|
expected_attributes = {
|
|
|
|
"frequency": 60,
|
|
|
|
"energy_exported": 10429451.9916853,
|
|
|
|
"energy_imported": 4824191.60668611,
|
|
|
|
"instant_average_voltage": 120.650001525879,
|
2020-04-10 11:33:58 -05:00
|
|
|
"unit_of_measurement": "kW",
|
2020-03-19 10:50:17 -05:00
|
|
|
"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
|
2020-04-10 11:33:58 -05:00
|
|
|
for key, value in expected_attributes.items():
|
|
|
|
assert state.attributes[key] == value
|
2020-03-19 10:50:17 -05:00
|
|
|
|
|
|
|
state = hass.states.get("sensor.powerwall_load_now")
|
|
|
|
assert state.state == "1.971"
|
|
|
|
expected_attributes = {
|
|
|
|
"frequency": 60,
|
|
|
|
"energy_exported": 1056797.48917483,
|
|
|
|
"energy_imported": 4692987.91889705,
|
|
|
|
"instant_average_voltage": 120.650001525879,
|
2020-04-10 11:33:58 -05:00
|
|
|
"unit_of_measurement": "kW",
|
2020-03-19 10:50:17 -05:00
|
|
|
"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
|
2020-04-10 11:33:58 -05:00
|
|
|
for key, value in expected_attributes.items():
|
|
|
|
assert state.attributes[key] == value
|
2020-03-19 10:50:17 -05:00
|
|
|
|
|
|
|
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,
|
2020-04-10 11:33:58 -05:00
|
|
|
"unit_of_measurement": "kW",
|
2020-03-19 10:50:17 -05:00
|
|
|
"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
|
2020-04-10 11:33:58 -05:00
|
|
|
for key, value in expected_attributes.items():
|
|
|
|
assert state.attributes[key] == value
|
2020-03-19 10:50:17 -05:00
|
|
|
|
|
|
|
state = hass.states.get("sensor.powerwall_solar_now")
|
|
|
|
assert state.state == "10.49"
|
|
|
|
expected_attributes = {
|
|
|
|
"frequency": 60,
|
|
|
|
"energy_exported": 9864205.82222448,
|
|
|
|
"energy_imported": 28177.5358355867,
|
|
|
|
"instant_average_voltage": 120.685001373291,
|
2020-04-10 11:33:58 -05:00
|
|
|
"unit_of_measurement": "kW",
|
2020-03-19 10:50:17 -05:00
|
|
|
"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
|
2020-04-10 11:33:58 -05:00
|
|
|
for key, value in expected_attributes.items():
|
|
|
|
assert state.attributes[key] == value
|
2020-03-19 10:50:17 -05:00
|
|
|
|
|
|
|
state = hass.states.get("sensor.powerwall_charge")
|
|
|
|
assert state.state == "47.32"
|
|
|
|
expected_attributes = {
|
2020-04-11 22:53:48 +02:00
|
|
|
"unit_of_measurement": UNIT_PERCENTAGE,
|
2020-03-19 10:50:17 -05:00
|
|
|
"friendly_name": "Powerwall Charge",
|
|
|
|
"device_class": "battery",
|
|
|
|
}
|
|
|
|
# Only test for a subset of attributes in case
|
|
|
|
# HA changes the implementation and a new one appears
|
2020-04-10 11:33:58 -05:00
|
|
|
for key, value in expected_attributes.items():
|
|
|
|
assert state.attributes[key] == value
|