Add more sensors to aurora_abb_powerone (#114074)
This commit is contained in:
parent
1c1d8d0317
commit
c82c295eed
4 changed files with 78 additions and 2 deletions
|
@ -36,8 +36,11 @@ class AuroraAbbDataUpdateCoordinator(DataUpdateCoordinator[dict[str, float]]):
|
||||||
try:
|
try:
|
||||||
self.client.connect()
|
self.client.connect()
|
||||||
|
|
||||||
# read ADC channel 3 (grid power output)
|
# See command 59 in the protocol manual linked in __init__.py
|
||||||
|
grid_voltage = self.client.measure(1, True)
|
||||||
|
grid_current = self.client.measure(2, True)
|
||||||
power_watts = self.client.measure(3, True)
|
power_watts = self.client.measure(3, True)
|
||||||
|
frequency = self.client.measure(4)
|
||||||
temperature_c = self.client.measure(21)
|
temperature_c = self.client.measure(21)
|
||||||
energy_wh = self.client.cumulated_energy(5)
|
energy_wh = self.client.cumulated_energy(5)
|
||||||
[alarm, *_] = self.client.alarms()
|
[alarm, *_] = self.client.alarms()
|
||||||
|
@ -57,7 +60,10 @@ class AuroraAbbDataUpdateCoordinator(DataUpdateCoordinator[dict[str, float]]):
|
||||||
)
|
)
|
||||||
sleep(1)
|
sleep(1)
|
||||||
else:
|
else:
|
||||||
|
data["grid_voltage"] = round(grid_voltage, 1)
|
||||||
|
data["grid_current"] = round(grid_current, 1)
|
||||||
data["instantaneouspower"] = round(power_watts, 1)
|
data["instantaneouspower"] = round(power_watts, 1)
|
||||||
|
data["grid_frequency"] = round(frequency, 1)
|
||||||
data["temp"] = round(temperature_c, 1)
|
data["temp"] = round(temperature_c, 1)
|
||||||
data["totalenergy"] = round(energy_wh / 1000, 2)
|
data["totalenergy"] = round(energy_wh / 1000, 2)
|
||||||
data["alarm"] = alarm
|
data["alarm"] = alarm
|
||||||
|
|
|
@ -18,7 +18,10 @@ from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_SERIAL_NUMBER,
|
ATTR_SERIAL_NUMBER,
|
||||||
EntityCategory,
|
EntityCategory,
|
||||||
|
UnitOfElectricCurrent,
|
||||||
|
UnitOfElectricPotential,
|
||||||
UnitOfEnergy,
|
UnitOfEnergy,
|
||||||
|
UnitOfFrequency,
|
||||||
UnitOfPower,
|
UnitOfPower,
|
||||||
UnitOfTemperature,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
|
@ -42,6 +45,32 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
ALARM_STATES = list(AuroraMapping.ALARM_STATES.values())
|
ALARM_STATES = list(AuroraMapping.ALARM_STATES.values())
|
||||||
|
|
||||||
SENSOR_TYPES = [
|
SENSOR_TYPES = [
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="grid_voltage",
|
||||||
|
device_class=SensorDeviceClass.VOLTAGE,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
translation_key="grid_voltage",
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="grid_current",
|
||||||
|
device_class=SensorDeviceClass.CURRENT,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
translation_key="grid_current",
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="grid_frequency",
|
||||||
|
device_class=SensorDeviceClass.FREQUENCY,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
native_unit_of_measurement=UnitOfFrequency.HERTZ,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key="alarm",
|
key="alarm",
|
||||||
device_class=SensorDeviceClass.ENUM,
|
device_class=SensorDeviceClass.ENUM,
|
||||||
|
|
|
@ -21,6 +21,12 @@
|
||||||
},
|
},
|
||||||
"entity": {
|
"entity": {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
"grid_voltage": {
|
||||||
|
"name": "Grid voltage"
|
||||||
|
},
|
||||||
|
"grid_current": {
|
||||||
|
"name": "Grid current"
|
||||||
|
},
|
||||||
"alarm": {
|
"alarm": {
|
||||||
"name": "Alarm status"
|
"name": "Alarm status"
|
||||||
},
|
},
|
||||||
|
|
|
@ -14,8 +14,10 @@ from homeassistant.components.aurora_abb_powerone.const import (
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SCAN_INTERVAL,
|
SCAN_INTERVAL,
|
||||||
)
|
)
|
||||||
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.const import ATTR_SERIAL_NUMBER, CONF_ADDRESS, CONF_PORT
|
from homeassistant.const import ATTR_SERIAL_NUMBER, CONF_ADDRESS, CONF_PORT
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity_registry import EntityRegistry, RegistryEntryDisabler
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||||
|
|
||||||
|
@ -30,7 +32,10 @@ TEST_CONFIG = {
|
||||||
|
|
||||||
def _simulated_returns(index, global_measure=None):
|
def _simulated_returns(index, global_measure=None):
|
||||||
returns = {
|
returns = {
|
||||||
|
1: 235.9476, # voltage
|
||||||
|
2: 2.7894, # current
|
||||||
3: 45.678, # power
|
3: 45.678, # power
|
||||||
|
4: 50.789, # frequency
|
||||||
21: 9.876, # temperature
|
21: 9.876, # temperature
|
||||||
5: 12345, # energy
|
5: 12345, # energy
|
||||||
}
|
}
|
||||||
|
@ -56,7 +61,7 @@ def _mock_config_entry():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_sensors(hass: HomeAssistant) -> None:
|
async def test_sensors(hass: HomeAssistant, entity_registry: EntityRegistry) -> None:
|
||||||
"""Test data coming back from inverter."""
|
"""Test data coming back from inverter."""
|
||||||
mock_entry = _mock_config_entry()
|
mock_entry = _mock_config_entry()
|
||||||
|
|
||||||
|
@ -97,6 +102,36 @@ async def test_sensors(hass: HomeAssistant) -> None:
|
||||||
assert energy
|
assert energy
|
||||||
assert energy.state == "12.35"
|
assert energy.state == "12.35"
|
||||||
|
|
||||||
|
# Test the 'disabled by default' sensors.
|
||||||
|
sensors = [
|
||||||
|
("sensor.mydevicename_grid_voltage", "235.9"),
|
||||||
|
("sensor.mydevicename_grid_current", "2.8"),
|
||||||
|
("sensor.mydevicename_frequency", "50.8"),
|
||||||
|
]
|
||||||
|
for entity_id, _ in sensors:
|
||||||
|
assert not hass.states.get(entity_id)
|
||||||
|
assert (
|
||||||
|
entry := entity_registry.async_get(entity_id)
|
||||||
|
), f"Entity registry entry for {entity_id} is missing"
|
||||||
|
assert entry.disabled
|
||||||
|
assert entry.disabled_by is RegistryEntryDisabler.INTEGRATION
|
||||||
|
|
||||||
|
# re-enable it
|
||||||
|
entity_registry.async_update_entity(entity_id=entity_id, disabled_by=None)
|
||||||
|
|
||||||
|
# must reload the integration when enabling an entity
|
||||||
|
await hass.config_entries.async_unload(mock_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert mock_entry.state is ConfigEntryState.NOT_LOADED
|
||||||
|
mock_entry.add_to_hass(hass)
|
||||||
|
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
for entity_id, value in sensors:
|
||||||
|
item = hass.states.get(entity_id)
|
||||||
|
assert item
|
||||||
|
assert item.state == value
|
||||||
|
|
||||||
|
|
||||||
async def test_sensor_dark(hass: HomeAssistant, freezer: FrozenDateTimeFactory) -> None:
|
async def test_sensor_dark(hass: HomeAssistant, freezer: FrozenDateTimeFactory) -> None:
|
||||||
"""Test that darkness (no comms) is handled correctly."""
|
"""Test that darkness (no comms) is handled correctly."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue