mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Add alarm sensor to Aurora ABB (#104503)
* Add new sensors * Add strings * Fix tests * Only add alarm sensor, & refactor * Address review comments * Address review comments. * Fix ruff
This commit is contained in:
parent
7480945465
commit
b48ad268b5
@ -76,6 +76,7 @@ class AuroraAbbDataUpdateCoordinator(DataUpdateCoordinator[dict[str, float]]):
|
|||||||
power_watts = self.client.measure(3, True)
|
power_watts = self.client.measure(3, True)
|
||||||
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()
|
||||||
except AuroraTimeoutError:
|
except AuroraTimeoutError:
|
||||||
self.available = False
|
self.available = False
|
||||||
_LOGGER.debug("No response from inverter (could be dark)")
|
_LOGGER.debug("No response from inverter (could be dark)")
|
||||||
@ -86,6 +87,7 @@ class AuroraAbbDataUpdateCoordinator(DataUpdateCoordinator[dict[str, float]]):
|
|||||||
data["instantaneouspower"] = round(power_watts, 1)
|
data["instantaneouspower"] = round(power_watts, 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
|
||||||
self.available = True
|
self.available = True
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
@ -5,6 +5,8 @@ from collections.abc import Mapping
|
|||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
from aurorapy.mapping import Mapping as AuroraMapping
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
SensorDeviceClass,
|
SensorDeviceClass,
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
@ -36,8 +38,16 @@ from .const import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
ALARM_STATES = list(AuroraMapping.ALARM_STATES.values())
|
||||||
|
|
||||||
SENSOR_TYPES = [
|
SENSOR_TYPES = [
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="alarm",
|
||||||
|
device_class=SensorDeviceClass.ENUM,
|
||||||
|
options=ALARM_STATES,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
translation_key="alarm",
|
||||||
|
),
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key="instantaneouspower",
|
key="instantaneouspower",
|
||||||
device_class=SensorDeviceClass.POWER,
|
device_class=SensorDeviceClass.POWER,
|
||||||
|
@ -21,11 +21,14 @@
|
|||||||
},
|
},
|
||||||
"entity": {
|
"entity": {
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
"alarm": {
|
||||||
|
"name": "Alarm status"
|
||||||
|
},
|
||||||
"power_output": {
|
"power_output": {
|
||||||
"name": "Power Output"
|
"name": "Power output"
|
||||||
},
|
},
|
||||||
"total_energy": {
|
"total_energy": {
|
||||||
"name": "Total Energy"
|
"name": "Total energy"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,8 @@ async def test_sensors(hass: HomeAssistant) -> None:
|
|||||||
with patch("aurorapy.client.AuroraSerialClient.connect", return_value=None), patch(
|
with patch("aurorapy.client.AuroraSerialClient.connect", return_value=None), patch(
|
||||||
"aurorapy.client.AuroraSerialClient.measure",
|
"aurorapy.client.AuroraSerialClient.measure",
|
||||||
side_effect=_simulated_returns,
|
side_effect=_simulated_returns,
|
||||||
|
), patch(
|
||||||
|
"aurorapy.client.AuroraSerialClient.alarms", return_value=["No alarm"]
|
||||||
), patch(
|
), patch(
|
||||||
"aurorapy.client.AuroraSerialClient.serial_number",
|
"aurorapy.client.AuroraSerialClient.serial_number",
|
||||||
return_value="9876543",
|
return_value="9876543",
|
||||||
@ -102,6 +104,8 @@ async def test_sensor_dark(hass: HomeAssistant, freezer: FrozenDateTimeFactory)
|
|||||||
# sun is up
|
# sun is up
|
||||||
with patch("aurorapy.client.AuroraSerialClient.connect", return_value=None), patch(
|
with patch("aurorapy.client.AuroraSerialClient.connect", return_value=None), patch(
|
||||||
"aurorapy.client.AuroraSerialClient.measure", side_effect=_simulated_returns
|
"aurorapy.client.AuroraSerialClient.measure", side_effect=_simulated_returns
|
||||||
|
), patch(
|
||||||
|
"aurorapy.client.AuroraSerialClient.alarms", return_value=["No alarm"]
|
||||||
), patch(
|
), patch(
|
||||||
"aurorapy.client.AuroraSerialClient.cumulated_energy",
|
"aurorapy.client.AuroraSerialClient.cumulated_energy",
|
||||||
side_effect=_simulated_returns,
|
side_effect=_simulated_returns,
|
||||||
@ -133,7 +137,7 @@ async def test_sensor_dark(hass: HomeAssistant, freezer: FrozenDateTimeFactory)
|
|||||||
), patch(
|
), patch(
|
||||||
"aurorapy.client.AuroraSerialClient.cumulated_energy",
|
"aurorapy.client.AuroraSerialClient.cumulated_energy",
|
||||||
side_effect=AuroraTimeoutError("No response after 3 tries"),
|
side_effect=AuroraTimeoutError("No response after 3 tries"),
|
||||||
):
|
), patch("aurorapy.client.AuroraSerialClient.alarms", return_value=["No alarm"]):
|
||||||
freezer.tick(SCAN_INTERVAL * 2)
|
freezer.tick(SCAN_INTERVAL * 2)
|
||||||
async_fire_time_changed(hass)
|
async_fire_time_changed(hass)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -145,7 +149,7 @@ async def test_sensor_dark(hass: HomeAssistant, freezer: FrozenDateTimeFactory)
|
|||||||
), patch(
|
), patch(
|
||||||
"aurorapy.client.AuroraSerialClient.cumulated_energy",
|
"aurorapy.client.AuroraSerialClient.cumulated_energy",
|
||||||
side_effect=_simulated_returns,
|
side_effect=_simulated_returns,
|
||||||
):
|
), patch("aurorapy.client.AuroraSerialClient.alarms", return_value=["No alarm"]):
|
||||||
freezer.tick(SCAN_INTERVAL * 4)
|
freezer.tick(SCAN_INTERVAL * 4)
|
||||||
async_fire_time_changed(hass)
|
async_fire_time_changed(hass)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -159,7 +163,7 @@ async def test_sensor_dark(hass: HomeAssistant, freezer: FrozenDateTimeFactory)
|
|||||||
), patch(
|
), patch(
|
||||||
"aurorapy.client.AuroraSerialClient.cumulated_energy",
|
"aurorapy.client.AuroraSerialClient.cumulated_energy",
|
||||||
side_effect=AuroraError("No response after 10 seconds"),
|
side_effect=AuroraError("No response after 10 seconds"),
|
||||||
):
|
), patch("aurorapy.client.AuroraSerialClient.alarms", return_value=["No alarm"]):
|
||||||
freezer.tick(SCAN_INTERVAL * 6)
|
freezer.tick(SCAN_INTERVAL * 6)
|
||||||
async_fire_time_changed(hass)
|
async_fire_time_changed(hass)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -174,6 +178,8 @@ async def test_sensor_unknown_error(hass: HomeAssistant) -> None:
|
|||||||
with patch("aurorapy.client.AuroraSerialClient.connect", return_value=None), patch(
|
with patch("aurorapy.client.AuroraSerialClient.connect", return_value=None), patch(
|
||||||
"aurorapy.client.AuroraSerialClient.measure",
|
"aurorapy.client.AuroraSerialClient.measure",
|
||||||
side_effect=AuroraError("another error"),
|
side_effect=AuroraError("another error"),
|
||||||
|
), patch(
|
||||||
|
"aurorapy.client.AuroraSerialClient.alarms", return_value=["No alarm"]
|
||||||
), patch("serial.Serial.isOpen", return_value=True):
|
), patch("serial.Serial.isOpen", return_value=True):
|
||||||
mock_entry.add_to_hass(hass)
|
mock_entry.add_to_hass(hass)
|
||||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user