Disable less popular Fronius entities by default (#60264)

This commit is contained in:
Matthias Alphart 2021-11-24 11:17:38 +01:00 committed by GitHub
parent 07c90575ac
commit 1a5f2c9c32
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 7 deletions

View file

@ -21,6 +21,7 @@ from homeassistant.const import (
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_CURRENT,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_FREQUENCY,
DEVICE_CLASS_POWER,
DEVICE_CLASS_POWER_FACTOR,
DEVICE_CLASS_TEMPERATURE,
@ -145,7 +146,9 @@ INVERTER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
key="frequency_ac",
name="Frequency AC",
native_unit_of_measurement=FREQUENCY_HERTZ,
device_class=DEVICE_CLASS_FREQUENCY,
state_class=STATE_CLASS_MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="current_ac",
@ -183,6 +186,7 @@ INVERTER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="voltage_dc",
@ -220,11 +224,13 @@ INVERTER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
key="led_state",
name="LED state",
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="led_color",
name="LED color",
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
entity_registry_enabled_default=False,
),
]
@ -256,6 +262,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
device_class=DEVICE_CLASS_CURRENT,
state_class=STATE_CLASS_MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="current_ac_phase_2",
@ -263,6 +270,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
device_class=DEVICE_CLASS_CURRENT,
state_class=STATE_CLASS_MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="current_ac_phase_3",
@ -270,6 +278,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
device_class=DEVICE_CLASS_CURRENT,
state_class=STATE_CLASS_MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="energy_reactive_ac_consumed",
@ -277,6 +286,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=ENERGY_VOLT_AMPERE_REACTIVE_HOUR,
state_class=STATE_CLASS_TOTAL_INCREASING,
icon="mdi:lightning-bolt-outline",
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="energy_reactive_ac_produced",
@ -284,6 +294,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=ENERGY_VOLT_AMPERE_REACTIVE_HOUR,
state_class=STATE_CLASS_TOTAL_INCREASING,
icon="mdi:lightning-bolt-outline",
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="energy_real_ac_minus",
@ -291,6 +302,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=ENERGY_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="energy_real_ac_plus",
@ -298,6 +310,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=ENERGY_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="energy_real_consumed",
@ -317,6 +330,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
key="frequency_phase_average",
name="Frequency phase average",
native_unit_of_measurement=FREQUENCY_HERTZ,
device_class=DEVICE_CLASS_FREQUENCY,
state_class=STATE_CLASS_MEASUREMENT,
),
SensorEntityDescription(
@ -330,6 +344,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=POWER_VOLT_AMPERE,
state_class=STATE_CLASS_MEASUREMENT,
icon="mdi:flash-outline",
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="power_apparent_phase_2",
@ -337,6 +352,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=POWER_VOLT_AMPERE,
state_class=STATE_CLASS_MEASUREMENT,
icon="mdi:flash-outline",
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="power_apparent_phase_3",
@ -344,6 +360,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=POWER_VOLT_AMPERE,
state_class=STATE_CLASS_MEASUREMENT,
icon="mdi:flash-outline",
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="power_apparent",
@ -351,24 +368,28 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=POWER_VOLT_AMPERE,
state_class=STATE_CLASS_MEASUREMENT,
icon="mdi:flash-outline",
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="power_factor_phase_1",
name="Power factor phase 1",
device_class=DEVICE_CLASS_POWER_FACTOR,
state_class=STATE_CLASS_MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="power_factor_phase_2",
name="Power factor phase 2",
device_class=DEVICE_CLASS_POWER_FACTOR,
state_class=STATE_CLASS_MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="power_factor_phase_3",
name="Power factor phase 3",
device_class=DEVICE_CLASS_POWER_FACTOR,
state_class=STATE_CLASS_MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="power_factor",
@ -382,6 +403,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=POWER_VOLT_AMPERE_REACTIVE,
state_class=STATE_CLASS_MEASUREMENT,
icon="mdi:flash-outline",
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="power_reactive_phase_2",
@ -389,6 +411,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=POWER_VOLT_AMPERE_REACTIVE,
state_class=STATE_CLASS_MEASUREMENT,
icon="mdi:flash-outline",
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="power_reactive_phase_3",
@ -396,6 +419,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=POWER_VOLT_AMPERE_REACTIVE,
state_class=STATE_CLASS_MEASUREMENT,
icon="mdi:flash-outline",
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="power_reactive",
@ -403,6 +427,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=POWER_VOLT_AMPERE_REACTIVE,
state_class=STATE_CLASS_MEASUREMENT,
icon="mdi:flash-outline",
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="power_real_phase_1",
@ -410,6 +435,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER,
state_class=STATE_CLASS_MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="power_real_phase_2",
@ -417,6 +443,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER,
state_class=STATE_CLASS_MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="power_real_phase_3",
@ -424,6 +451,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER,
state_class=STATE_CLASS_MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="power_real",
@ -438,6 +466,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="voltage_ac_phase_2",
@ -445,6 +474,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="voltage_ac_phase_3",
@ -452,6 +482,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="voltage_ac_phase_to_phase_12",
@ -459,6 +490,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="voltage_ac_phase_to_phase_23",
@ -466,6 +498,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="voltage_ac_phase_to_phase_31",
@ -473,6 +506,7 @@ METER_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT,
entity_registry_enabled_default=False,
),
]
@ -483,6 +517,7 @@ POWER_FLOW_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=ENERGY_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="energy_year",
@ -490,6 +525,7 @@ POWER_FLOW_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=ENERGY_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="energy_total",
@ -497,6 +533,7 @@ POWER_FLOW_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
native_unit_of_measurement=ENERGY_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="meter_mode",
@ -552,11 +589,13 @@ STORAGE_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
key="capacity_maximum",
name="Capacity maximum",
native_unit_of_measurement=ELECTRIC_CHARGE_AMPERE_HOURS,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
SensorEntityDescription(
key="capacity_designed",
name="Capacity designed",
native_unit_of_measurement=ELECTRIC_CHARGE_AMPERE_HOURS,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
SensorEntityDescription(
key="current_dc",
@ -581,6 +620,7 @@ STORAGE_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT,
icon="mdi:current-dc",
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="voltage_dc_minimum_cell",
@ -589,6 +629,7 @@ STORAGE_ENTITY_DESCRIPTIONS: list[SensorEntityDescription] = [
device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT,
icon="mdi:current-dc",
entity_registry_enabled_default=False,
),
SensorEntityDescription(
key="state_of_charge",

View file

@ -1,8 +1,10 @@
"""Tests for the Fronius integration."""
from homeassistant.components.fronius.const import DOMAIN
from homeassistant.const import CONF_HOST
from homeassistant.helpers import entity_registry as er
from homeassistant.util import dt
from tests.common import MockConfigEntry, load_fixture
from tests.common import MockConfigEntry, async_fire_time_changed, load_fixture
from tests.test_util.aiohttp import AiohttpClientMocker
MOCK_HOST = "http://fronius"
@ -22,6 +24,7 @@ async def setup_fronius_integration(hass):
entry.add_to_hass(hass)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
return entry
def mock_responses(
@ -70,3 +73,16 @@ def mock_responses(
f"{host}/solar_api/v1/GetStorageRealtimeData.cgi?Scope=System",
text=load_fixture("symo/GetStorageRealtimeData_System.json", "fronius"),
)
async def enable_all_entities(hass, config_entry_id, time_till_next_update):
"""Enable all entities for a config entry and fast forward time to receive data."""
registry = er.async_get(hass)
entities = er.async_entries_for_config_entry(registry, config_entry_id)
for entry in [
entry for entry in entities if entry.disabled_by == er.DISABLED_INTEGRATION
]:
registry.async_update_entity(entry.entity_id, **{"disabled_by": None})
await hass.async_block_till_done()
async_fire_time_changed(hass, dt.utcnow() + time_till_next_update)
await hass.async_block_till_done()

View file

@ -1,13 +1,14 @@
"""Tests for the Fronius sensor platform."""
from homeassistant.components.fronius.coordinator import (
FroniusInverterUpdateCoordinator,
FroniusMeterUpdateCoordinator,
FroniusPowerFlowUpdateCoordinator,
)
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.const import STATE_UNKNOWN
from homeassistant.util import dt
from . import mock_responses, setup_fronius_integration
from . import enable_all_entities, mock_responses, setup_fronius_integration
from tests.common import async_fire_time_changed
@ -21,8 +22,12 @@ async def test_symo_inverter(hass, aioclient_mock):
# Init at night
mock_responses(aioclient_mock, night=True)
await setup_fronius_integration(hass)
config_entry = await setup_fronius_integration(hass)
assert len(hass.states.async_all(domain_filter=SENSOR_DOMAIN)) == 23
await enable_all_entities(
hass, config_entry.entry_id, FroniusInverterUpdateCoordinator.default_interval
)
assert len(hass.states.async_all(domain_filter=SENSOR_DOMAIN)) == 55
assert_state("sensor.current_dc_fronius_inverter_1_http_fronius", 0)
assert_state("sensor.energy_day_fronius_inverter_1_http_fronius", 10828)
@ -36,7 +41,10 @@ async def test_symo_inverter(hass, aioclient_mock):
hass, dt.utcnow() + FroniusInverterUpdateCoordinator.default_interval
)
await hass.async_block_till_done()
assert len(hass.states.async_all(domain_filter=SENSOR_DOMAIN)) == 57
await enable_all_entities(
hass, config_entry.entry_id, FroniusInverterUpdateCoordinator.default_interval
)
assert len(hass.states.async_all(domain_filter=SENSOR_DOMAIN)) == 59
# 4 additional AC entities
assert_state("sensor.current_dc_fronius_inverter_1_http_fronius", 2.19)
@ -60,8 +68,8 @@ async def test_symo_logger(hass, aioclient_mock):
mock_responses(aioclient_mock)
await setup_fronius_integration(hass)
assert len(hass.states.async_all(domain_filter=SENSOR_DOMAIN)) == 25
assert len(hass.states.async_all(domain_filter=SENSOR_DOMAIN)) == 59
# ignored constant entities:
# hardware_platform, hardware_version, product_type
# software_version, time_zone, time_zone_location
@ -91,8 +99,12 @@ async def test_symo_meter(hass, aioclient_mock):
assert state.state == str(expected_state)
mock_responses(aioclient_mock)
await setup_fronius_integration(hass)
config_entry = await setup_fronius_integration(hass)
assert len(hass.states.async_all(domain_filter=SENSOR_DOMAIN)) == 25
await enable_all_entities(
hass, config_entry.entry_id, FroniusMeterUpdateCoordinator.default_interval
)
assert len(hass.states.async_all(domain_filter=SENSOR_DOMAIN)) == 59
# ignored entities:
# manufacturer, model, serial, enable, timestamp, visible, meter_location
@ -152,8 +164,12 @@ async def test_symo_power_flow(hass, aioclient_mock):
# First test at night
mock_responses(aioclient_mock, night=True)
await setup_fronius_integration(hass)
config_entry = await setup_fronius_integration(hass)
assert len(hass.states.async_all(domain_filter=SENSOR_DOMAIN)) == 23
await enable_all_entities(
hass, config_entry.entry_id, FroniusInverterUpdateCoordinator.default_interval
)
assert len(hass.states.async_all(domain_filter=SENSOR_DOMAIN)) == 55
# ignored: location, mode, timestamp
#