Add inverters to Autarco integration (#121779)

pull/121810/head^2
Klaas Schoute 2024-07-12 16:54:22 +02:00 committed by GitHub
parent a8321fac95
commit 0d27cdc845
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 743 additions and 20 deletions

View File

@ -9,5 +9,3 @@ from typing import Final
DOMAIN: Final = "autarco"
LOGGER = logging.getLogger(__package__)
SCAN_INTERVAL = timedelta(minutes=5)
SENSORS_SOLAR: Final = "solar"

View File

@ -4,7 +4,7 @@ from __future__ import annotations
from typing import NamedTuple
from autarco import AccountSite, Autarco, Solar
from autarco import AccountSite, Autarco, Inverter, Solar
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
@ -17,6 +17,7 @@ class AutarcoData(NamedTuple):
"""Class for defining data in dict."""
solar: Solar
inverters: dict[str, Inverter]
class AutarcoDataUpdateCoordinator(DataUpdateCoordinator[AutarcoData]):
@ -44,4 +45,5 @@ class AutarcoDataUpdateCoordinator(DataUpdateCoordinator[AutarcoData]):
"""Fetch data from Autarco API."""
return AutarcoData(
solar=await self.client.get_solar(self.site.public_key),
inverters=await self.client.get_inverters(self.site.public_key),
)

View File

@ -27,6 +27,16 @@ async def async_get_config_entry_diagnostics(
"energy_production_month": coordinator.data.solar.energy_production_month,
"energy_production_total": coordinator.data.solar.energy_production_total,
},
"inverters": [
{
"serial_number": inverter.serial_number,
"out_ac_power": inverter.out_ac_power,
"out_ac_energy_total": inverter.out_ac_energy_total,
"grid_turned_off": inverter.grid_turned_off,
"health": inverter.health,
}
for inverter in coordinator.data.inverters.values()
],
}
for coordinator in autarco_data
],

View File

@ -5,7 +5,7 @@ from __future__ import annotations
from collections.abc import Callable
from dataclasses import dataclass
from autarco import Solar
from autarco import Inverter, Solar
from homeassistant.components.sensor import (
SensorDeviceClass,
@ -29,7 +29,7 @@ from .coordinator import AutarcoDataUpdateCoordinator
class AutarcoSolarSensorEntityDescription(SensorEntityDescription):
"""Describes an Autarco sensor entity."""
state: Callable[[Solar], StateType]
value_fn: Callable[[Solar], StateType]
SENSORS_SOLAR: tuple[AutarcoSolarSensorEntityDescription, ...] = (
@ -39,21 +39,21 @@ SENSORS_SOLAR: tuple[AutarcoSolarSensorEntityDescription, ...] = (
native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
state=lambda solar: solar.power_production,
value_fn=lambda solar: solar.power_production,
),
AutarcoSolarSensorEntityDescription(
key="energy_production_today",
translation_key="energy_production_today",
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY,
state=lambda solar: solar.energy_production_today,
value_fn=lambda solar: solar.energy_production_today,
),
AutarcoSolarSensorEntityDescription(
key="energy_production_month",
translation_key="energy_production_month",
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY,
state=lambda solar: solar.energy_production_month,
value_fn=lambda solar: solar.energy_production_month,
),
AutarcoSolarSensorEntityDescription(
key="energy_production_total",
@ -61,7 +61,34 @@ SENSORS_SOLAR: tuple[AutarcoSolarSensorEntityDescription, ...] = (
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
state=lambda solar: solar.energy_production_total,
value_fn=lambda solar: solar.energy_production_total,
),
)
@dataclass(frozen=True, kw_only=True)
class AutarcoInverterSensorEntityDescription(SensorEntityDescription):
"""Describes an Autarco inverter sensor entity."""
value_fn: Callable[[Inverter], StateType]
SENSORS_INVERTER: tuple[AutarcoInverterSensorEntityDescription, ...] = (
AutarcoInverterSensorEntityDescription(
key="out_ac_power",
translation_key="out_ac_power",
native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
value_fn=lambda inverter: inverter.out_ac_power,
),
AutarcoInverterSensorEntityDescription(
key="out_ac_energy_total",
translation_key="out_ac_energy_total",
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
value_fn=lambda inverter: inverter.out_ac_energy_total,
),
)
@ -72,14 +99,25 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up Autarco sensors based on a config entry."""
entities: list[SensorEntity] = []
for coordinator in entry.runtime_data:
async_add_entities(
entities.extend(
AutarcoSolarSensorEntity(
coordinator=coordinator,
description=description,
)
for description in SENSORS_SOLAR
)
entities.extend(
AutarcoInverterSensorEntity(
coordinator=coordinator,
description=description,
serial_number=inverter,
)
for description in SENSORS_INVERTER
for inverter in coordinator.data.inverters
)
async_add_entities(entities)
class AutarcoSolarSensorEntity(
@ -111,4 +149,41 @@ class AutarcoSolarSensorEntity(
@property
def native_value(self) -> StateType:
"""Return the state of the sensor."""
return self.entity_description.state(self.coordinator.data.solar)
return self.entity_description.value_fn(self.coordinator.data.solar)
class AutarcoInverterSensorEntity(
CoordinatorEntity[AutarcoDataUpdateCoordinator], SensorEntity
):
"""Defines an Autarco inverter sensor."""
entity_description: AutarcoInverterSensorEntityDescription
_attr_has_entity_name = True
def __init__(
self,
*,
coordinator: AutarcoDataUpdateCoordinator,
description: AutarcoInverterSensorEntityDescription,
serial_number: str,
) -> None:
"""Initialize Autarco sensor."""
super().__init__(coordinator)
self.entity_description = description
self._serial_number = serial_number
self._attr_unique_id = f"{serial_number}_{description.key}"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, serial_number)},
name=f"Inverter {serial_number}",
manufacturer="Autarco",
model="Inverter",
serial_number=serial_number,
)
@property
def native_value(self) -> StateType:
"""Return the state of the sensor."""
return self.entity_description.value_fn(
self.coordinator.data.inverters[self._serial_number]
)

View File

@ -34,6 +34,12 @@
},
"energy_production_total": {
"name": "Energy production total"
},
"out_ac_power": {
"name": "Power AC output"
},
"out_ac_energy_total": {
"name": "Energy AC output total"
}
}
}

View File

@ -3,7 +3,7 @@
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
from autarco import AccountSite, Solar
from autarco import AccountSite, Inverter, Solar
import pytest
from homeassistant.components.autarco.const import DOMAIN
@ -50,6 +50,22 @@ def mock_autarco_client() -> Generator[AsyncMock]:
energy_production_month=58,
energy_production_total=10379,
)
client.get_inverters.return_value = {
"test-serial-1": Inverter(
serial_number="test-serial-1",
out_ac_power=200,
out_ac_energy_total=10379,
grid_turned_off=False,
health="OK",
),
"test-serial-2": Inverter(
serial_number="test-serial-2",
out_ac_power=500,
out_ac_energy_total=10379,
grid_turned_off=False,
health="OK",
),
}
yield client

View File

@ -1,6 +0,0 @@
{
"pv_now": 200,
"pv_today": 4,
"pv_month": 58,
"pv_to_date": 10379
}

View File

@ -5,6 +5,22 @@
dict({
'health': 'OK',
'id': 1,
'inverters': list([
dict({
'grid_turned_off': False,
'health': 'OK',
'out_ac_energy_total': 10379,
'out_ac_power': 200,
'serial_number': 'test-serial-1',
}),
dict({
'grid_turned_off': False,
'health': 'OK',
'out_ac_energy_total': 10379,
'out_ac_power': 500,
'serial_number': 'test-serial-2',
}),
]),
'name': 'test-system',
'solar': dict({
'energy_production_month': 58,

View File

@ -1,4 +1,610 @@
# serializer version: 1
# name: test_all_sensors[sensor.inverter_test_serial_1_energy_ac_output_total-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.inverter_test_serial_1_energy_ac_output_total',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.ENERGY: 'energy'>,
'original_icon': None,
'original_name': 'Energy AC output total',
'platform': 'autarco',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'out_ac_energy_total',
'unique_id': 'test-serial-1_out_ac_energy_total',
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
})
# ---
# name: test_all_sensors[sensor.inverter_test_serial_1_energy_ac_output_total-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'energy',
'friendly_name': 'Inverter test-serial-1 Energy AC output total',
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
}),
'context': <ANY>,
'entity_id': 'sensor.inverter_test_serial_1_energy_ac_output_total',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '10379',
})
# ---
# name: test_all_sensors[sensor.inverter_test_serial_1_power_ac_output-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.inverter_test_serial_1_power_ac_output',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.POWER: 'power'>,
'original_icon': None,
'original_name': 'Power AC output',
'platform': 'autarco',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'out_ac_power',
'unique_id': 'test-serial-1_out_ac_power',
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
})
# ---
# name: test_all_sensors[sensor.inverter_test_serial_1_power_ac_output-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'power',
'friendly_name': 'Inverter test-serial-1 Power AC output',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
}),
'context': <ANY>,
'entity_id': 'sensor.inverter_test_serial_1_power_ac_output',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '200',
})
# ---
# name: test_all_sensors[sensor.inverter_test_serial_2_energy_ac_output_total-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.inverter_test_serial_2_energy_ac_output_total',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.ENERGY: 'energy'>,
'original_icon': None,
'original_name': 'Energy AC output total',
'platform': 'autarco',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'out_ac_energy_total',
'unique_id': 'test-serial-2_out_ac_energy_total',
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
})
# ---
# name: test_all_sensors[sensor.inverter_test_serial_2_energy_ac_output_total-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'energy',
'friendly_name': 'Inverter test-serial-2 Energy AC output total',
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
}),
'context': <ANY>,
'entity_id': 'sensor.inverter_test_serial_2_energy_ac_output_total',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '10379',
})
# ---
# name: test_all_sensors[sensor.inverter_test_serial_2_power_ac_output-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.inverter_test_serial_2_power_ac_output',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.POWER: 'power'>,
'original_icon': None,
'original_name': 'Power AC output',
'platform': 'autarco',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'out_ac_power',
'unique_id': 'test-serial-2_out_ac_power',
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
})
# ---
# name: test_all_sensors[sensor.inverter_test_serial_2_power_ac_output-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'power',
'friendly_name': 'Inverter test-serial-2 Power AC output',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
}),
'context': <ANY>,
'entity_id': 'sensor.inverter_test_serial_2_power_ac_output',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '500',
})
# ---
# name: test_all_sensors[sensor.solar_energy_production_month-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.solar_energy_production_month',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.ENERGY: 'energy'>,
'original_icon': None,
'original_name': 'Energy production month',
'platform': 'autarco',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'energy_production_month',
'unique_id': '1_solar_energy_production_month',
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
})
# ---
# name: test_all_sensors[sensor.solar_energy_production_month-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'energy',
'friendly_name': 'Solar Energy production month',
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
}),
'context': <ANY>,
'entity_id': 'sensor.solar_energy_production_month',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '58',
})
# ---
# name: test_all_sensors[sensor.solar_energy_production_today-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.solar_energy_production_today',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.ENERGY: 'energy'>,
'original_icon': None,
'original_name': 'Energy production today',
'platform': 'autarco',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'energy_production_today',
'unique_id': '1_solar_energy_production_today',
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
})
# ---
# name: test_all_sensors[sensor.solar_energy_production_today-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'energy',
'friendly_name': 'Solar Energy production today',
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
}),
'context': <ANY>,
'entity_id': 'sensor.solar_energy_production_today',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '4',
})
# ---
# name: test_all_sensors[sensor.solar_energy_production_total-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.solar_energy_production_total',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.ENERGY: 'energy'>,
'original_icon': None,
'original_name': 'Energy production total',
'platform': 'autarco',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'energy_production_total',
'unique_id': '1_solar_energy_production_total',
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
})
# ---
# name: test_all_sensors[sensor.solar_energy_production_total-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'energy',
'friendly_name': 'Solar Energy production total',
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
}),
'context': <ANY>,
'entity_id': 'sensor.solar_energy_production_total',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '10379',
})
# ---
# name: test_all_sensors[sensor.solar_power_production-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.solar_power_production',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.POWER: 'power'>,
'original_icon': None,
'original_name': 'Power production',
'platform': 'autarco',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'power_production',
'unique_id': '1_solar_power_production',
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
})
# ---
# name: test_all_sensors[sensor.solar_power_production-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'power',
'friendly_name': 'Solar Power production',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
}),
'context': <ANY>,
'entity_id': 'sensor.solar_power_production',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '200',
})
# ---
# name: test_solar_sensors[sensor.inverter_test_serial_1_energy_ac_output_total-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.inverter_test_serial_1_energy_ac_output_total',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.ENERGY: 'energy'>,
'original_icon': None,
'original_name': 'Energy AC output total',
'platform': 'autarco',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'out_ac_energy_total',
'unique_id': 'test-serial-1_out_ac_energy_total',
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
})
# ---
# name: test_solar_sensors[sensor.inverter_test_serial_1_energy_ac_output_total-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'energy',
'friendly_name': 'Inverter test-serial-1 Energy AC output total',
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
}),
'context': <ANY>,
'entity_id': 'sensor.inverter_test_serial_1_energy_ac_output_total',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '10379',
})
# ---
# name: test_solar_sensors[sensor.inverter_test_serial_1_power_ac_output-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.inverter_test_serial_1_power_ac_output',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.POWER: 'power'>,
'original_icon': None,
'original_name': 'Power AC output',
'platform': 'autarco',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'out_ac_power',
'unique_id': 'test-serial-1_out_ac_power',
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
})
# ---
# name: test_solar_sensors[sensor.inverter_test_serial_1_power_ac_output-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'power',
'friendly_name': 'Inverter test-serial-1 Power AC output',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
}),
'context': <ANY>,
'entity_id': 'sensor.inverter_test_serial_1_power_ac_output',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '200',
})
# ---
# name: test_solar_sensors[sensor.inverter_test_serial_2_energy_ac_output_total-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.inverter_test_serial_2_energy_ac_output_total',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.ENERGY: 'energy'>,
'original_icon': None,
'original_name': 'Energy AC output total',
'platform': 'autarco',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'out_ac_energy_total',
'unique_id': 'test-serial-2_out_ac_energy_total',
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
})
# ---
# name: test_solar_sensors[sensor.inverter_test_serial_2_energy_ac_output_total-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'energy',
'friendly_name': 'Inverter test-serial-2 Energy AC output total',
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
}),
'context': <ANY>,
'entity_id': 'sensor.inverter_test_serial_2_energy_ac_output_total',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '10379',
})
# ---
# name: test_solar_sensors[sensor.inverter_test_serial_2_power_ac_output-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.inverter_test_serial_2_power_ac_output',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.POWER: 'power'>,
'original_icon': None,
'original_name': 'Power AC output',
'platform': 'autarco',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': 'out_ac_power',
'unique_id': 'test-serial-2_out_ac_power',
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
})
# ---
# name: test_solar_sensors[sensor.inverter_test_serial_2_power_ac_output-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'power',
'friendly_name': 'Inverter test-serial-2 Power AC output',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': <UnitOfPower.WATT: 'W'>,
}),
'context': <ANY>,
'entity_id': 'sensor.inverter_test_serial_2_power_ac_output',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': '500',
})
# ---
# name: test_solar_sensors[sensor.solar_energy_production_month-entry]
EntityRegistryEntrySnapshot({
'aliases': set({

View File

@ -13,14 +13,14 @@ from . import setup_integration
from tests.common import MockConfigEntry, snapshot_platform
async def test_solar_sensors(
async def test_all_sensors(
hass: HomeAssistant,
mock_autarco_client: MagicMock,
mock_config_entry: MockConfigEntry,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
) -> None:
"""Test the Autarco - Solar sensor."""
"""Test the Autarco sensors."""
with patch("homeassistant.components.autarco.PLATFORMS", [Platform.SENSOR]):
await setup_integration(hass, mock_config_entry)