Skip to content

Commit d5132e8

Browse files
Imeon-EnergyTheBushBoyjoostlekNoRi2909
authored
Add select to Imeon inverter integration (home-assistant#150889)
Co-authored-by: TheBushBoy <[email protected]> Co-authored-by: Joost Lekkerkerker <[email protected]> Co-authored-by: Norbert Rittel <[email protected]>
1 parent 1bcf3cf commit d5132e8

File tree

9 files changed

+324
-108
lines changed

9 files changed

+324
-108
lines changed

homeassistant/components/imeon_inverter/const.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@
55
DOMAIN = "imeon_inverter"
66
TIMEOUT = 30
77
PLATFORMS = [
8+
Platform.SELECT,
89
Platform.SENSOR,
910
]
1011
ATTR_BATTERY_STATUS = ["charging", "discharging", "charged"]
12+
ATTR_INVERTER_MODE = {
13+
"smg": "smart_grid",
14+
"bup": "backup",
15+
"ong": "on_grid",
16+
"ofg": "off_grid",
17+
}
18+
INVERTER_MODE_OPTIONS = {v: k for k, v in ATTR_INVERTER_MODE.items()}
1119
ATTR_INVERTER_STATE = [
1220
"not_connected",
1321
"unsynchronized",

homeassistant/components/imeon_inverter/icons.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@
170170
"energy_battery_consumed": {
171171
"default": "mdi:battery-arrow-down-outline"
172172
}
173+
},
174+
"select": {
175+
"manager_inverter_mode": {
176+
"default": "mdi:view-grid"
177+
}
173178
}
174179
}
175180
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
"""Imeon inverter select support."""
2+
3+
from collections.abc import Awaitable, Callable
4+
from dataclasses import dataclass
5+
import logging
6+
7+
from homeassistant.components.select import SelectEntity, SelectEntityDescription
8+
from homeassistant.config_entries import ConfigEntry
9+
from homeassistant.const import EntityCategory
10+
from homeassistant.core import HomeAssistant
11+
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
12+
13+
from .const import ATTR_INVERTER_MODE, INVERTER_MODE_OPTIONS
14+
from .coordinator import Inverter, InverterCoordinator
15+
from .entity import InverterEntity
16+
17+
type InverterConfigEntry = ConfigEntry[InverterCoordinator]
18+
19+
_LOGGER = logging.getLogger(__name__)
20+
21+
22+
@dataclass(frozen=True, kw_only=True)
23+
class ImeonSelectEntityDescription(SelectEntityDescription):
24+
"""Class to describe an Imeon inverter select entity."""
25+
26+
set_value_fn: Callable[[Inverter, str], Awaitable[bool]]
27+
values: dict[str, str]
28+
29+
30+
SELECT_DESCRIPTIONS: tuple[ImeonSelectEntityDescription, ...] = (
31+
ImeonSelectEntityDescription(
32+
key="manager_inverter_mode",
33+
translation_key="manager_inverter_mode",
34+
options=list(INVERTER_MODE_OPTIONS),
35+
values=ATTR_INVERTER_MODE,
36+
set_value_fn=lambda api, mode: api.set_inverter_mode(
37+
INVERTER_MODE_OPTIONS[mode]
38+
),
39+
),
40+
)
41+
42+
43+
async def async_setup_entry(
44+
hass: HomeAssistant,
45+
entry: InverterConfigEntry,
46+
async_add_entities: AddConfigEntryEntitiesCallback,
47+
) -> None:
48+
"""Create each select for a given config entry."""
49+
coordinator = entry.runtime_data
50+
async_add_entities(
51+
InverterSelect(coordinator, entry, description)
52+
for description in SELECT_DESCRIPTIONS
53+
)
54+
55+
56+
class InverterSelect(InverterEntity, SelectEntity):
57+
"""Representation of an Imeon inverter select."""
58+
59+
entity_description: ImeonSelectEntityDescription
60+
_attr_entity_category = EntityCategory.CONFIG
61+
62+
@property
63+
def current_option(self) -> str | None:
64+
"""Return the state of the select."""
65+
value = self.coordinator.data.get(self.data_key)
66+
if not isinstance(value, str):
67+
return None
68+
return self.entity_description.values.get(value)
69+
70+
async def async_select_option(self, option: str) -> None:
71+
"""Change the selected option."""
72+
await self.entity_description.set_value_fn(self.coordinator.api, option)

homeassistant/components/imeon_inverter/strings.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
"unsynchronized": "Unsynchronized",
9696
"grid_consumption": "Grid consumption",
9797
"grid_injection": "Grid injection",
98-
"grid_synchronised_but_not_used": "Grid unsynchronized but used"
98+
"grid_synchronized_but_not_used": "Grid unsynchronized but used"
9999
}
100100
},
101101
"meter_power": {
@@ -214,6 +214,17 @@
214214
"energy_battery_consumed": {
215215
"name": "Today battery-consumed energy"
216216
}
217+
},
218+
"select": {
219+
"manager_inverter_mode": {
220+
"name": "Inverter mode",
221+
"state": {
222+
"smart_grid": "Smart grid",
223+
"backup": "Backup",
224+
"on_grid": "On-grid",
225+
"off_grid": "Off-grid"
226+
}
227+
}
217228
}
218229
}
219230
}
Lines changed: 56 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,82 @@
11
{
22
"battery": {
3-
"battery_power": 2500.0,
4-
"battery_soc": 78.0,
5-
"battery_status": "charging",
6-
"battery_stored": 10200.0,
7-
"battery_consumed": 500.0
3+
"power": 2500.0,
4+
"soc": 78.0,
5+
"status": "charging",
6+
"stored": 10200.0,
7+
"consumed": 500.0
88
},
99
"grid": {
10-
"grid_current_l1": 12.5,
11-
"grid_current_l2": 10.8,
12-
"grid_current_l3": 11.2,
13-
"grid_frequency": 50.0,
14-
"grid_voltage_l1": 230.0,
15-
"grid_voltage_l2": 229.5,
16-
"grid_voltage_l3": 230.1
10+
"current_l1": 12.5,
11+
"current_l2": 10.8,
12+
"current_l3": 11.2,
13+
"frequency": 50.0,
14+
"voltage_l1": 230.0,
15+
"voltage_l2": 229.5,
16+
"voltage_l3": 230.1
1717
},
1818
"input": {
19-
"input_power_l1": 1000.0,
20-
"input_power_l2": 950.0,
21-
"input_power_l3": 980.0,
22-
"input_power_total": 2930.0
19+
"power_l1": 1000.0,
20+
"power_l2": 950.0,
21+
"power_l3": 980.0,
22+
"power_total": 2930.0
2323
},
2424
"inverter": {
25-
"inverter_charging_current_limit": 50,
26-
"inverter_injection_power_limit": 5000.0,
27-
"manager_inverter_state": "grid_consumption"
25+
"charging_current_limit": 50,
26+
"injection_power_limit": 5000.0
27+
},
28+
"manager": {
29+
"inverter_state": "grid_consumption",
30+
"inverter_mode": "smg"
2831
},
2932
"meter": {
30-
"meter_power": 2000.0
33+
"power": 2000.0
3134
},
3235
"output": {
33-
"output_current_l1": 15.0,
34-
"output_current_l2": 14.5,
35-
"output_current_l3": 15.2,
36-
"output_frequency": 49.9,
37-
"output_power_l1": 1100.0,
38-
"output_power_l2": 1080.0,
39-
"output_power_l3": 1120.0,
40-
"output_power_total": 3300.0,
41-
"output_voltage_l1": 231.0,
42-
"output_voltage_l2": 229.8,
43-
"output_voltage_l3": 230.2
36+
"current_l1": 15.0,
37+
"current_l2": 14.5,
38+
"current_l3": 15.2,
39+
"frequency": 49.9,
40+
"power_l1": 1100.0,
41+
"power_l2": 1080.0,
42+
"power_l3": 1120.0,
43+
"power_total": 3300.0,
44+
"voltage_l1": 231.0,
45+
"voltage_l2": 229.8,
46+
"voltage_l3": 230.2
4447
},
4548
"pv": {
46-
"pv_consumed": 1500.0,
47-
"pv_injected": 800.0,
48-
"pv_power_1": 1200.0,
49-
"pv_power_2": 1300.0,
50-
"pv_power_total": 2500.0
49+
"consumed": 1500.0,
50+
"injected": 800.0,
51+
"power_1": 1200.0,
52+
"power_2": 1300.0,
53+
"power_total": 2500.0
5154
},
5255
"temp": {
53-
"temp_air_temperature": 25.0,
54-
"temp_component_temperature": 45.5
56+
"air_temperature": 25.0,
57+
"component_temperature": 45.5
5558
},
5659
"monitoring": {
57-
"monitoring_self_produced": 2600.0,
58-
"monitoring_self_consumption": 85.0,
59-
"monitoring_self_sufficiency": 90.0
60+
"self_produced": 2600.0,
61+
"self_consumption": 85.0,
62+
"self_sufficiency": 90.0
6063
},
6164
"monitoring_minute": {
62-
"monitoring_minute_building_consumption": 50.0,
63-
"monitoring_minute_grid_consumption": 8.3,
64-
"monitoring_minute_grid_injection": 11.7,
65-
"monitoring_minute_grid_power_flow": -3.4,
66-
"monitoring_minute_solar_production": 43.3
65+
"building_consumption": 50.0,
66+
"grid_consumption": 8.3,
67+
"grid_injection": 11.7,
68+
"grid_power_flow": -3.4,
69+
"solar_production": 43.3
6770
},
6871
"timeline": {
69-
"timeline_type_msg": "info_bat"
72+
"type_msg": "info_bat"
7073
},
7174
"energy": {
72-
"energy_pv": 12000.0,
73-
"energy_grid_injected": 5000.0,
74-
"energy_grid_consumed": 6000.0,
75-
"energy_building_consumption": 15000.0,
76-
"energy_battery_stored": 8000.0,
77-
"energy_battery_consumed": 2000.0
75+
"pv": 12000.0,
76+
"grid_injected": 5000.0,
77+
"grid_consumed": 6000.0,
78+
"building_consumption": 15000.0,
79+
"battery_stored": 8000.0,
80+
"battery_consumed": 2000.0
7881
}
7982
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# serializer version: 1
2+
# name: test_selects[select.imeon_inverter_inverter_mode-entry]
3+
EntityRegistryEntrySnapshot({
4+
'aliases': set({
5+
}),
6+
'area_id': None,
7+
'capabilities': dict({
8+
'options': list([
9+
'smart_grid',
10+
'backup',
11+
'on_grid',
12+
'off_grid',
13+
]),
14+
}),
15+
'config_entry_id': <ANY>,
16+
'config_subentry_id': <ANY>,
17+
'device_class': None,
18+
'device_id': <ANY>,
19+
'disabled_by': None,
20+
'domain': 'select',
21+
'entity_category': <EntityCategory.CONFIG: 'config'>,
22+
'entity_id': 'select.imeon_inverter_inverter_mode',
23+
'has_entity_name': True,
24+
'hidden_by': None,
25+
'icon': None,
26+
'id': <ANY>,
27+
'labels': set({
28+
}),
29+
'name': None,
30+
'options': dict({
31+
}),
32+
'original_device_class': None,
33+
'original_icon': None,
34+
'original_name': 'Inverter mode',
35+
'platform': 'imeon_inverter',
36+
'previous_unique_id': None,
37+
'suggested_object_id': None,
38+
'supported_features': 0,
39+
'translation_key': 'manager_inverter_mode',
40+
'unique_id': '111111111111111_manager_inverter_mode',
41+
'unit_of_measurement': None,
42+
})
43+
# ---
44+
# name: test_selects[select.imeon_inverter_inverter_mode-state]
45+
StateSnapshot({
46+
'attributes': ReadOnlyDict({
47+
'friendly_name': 'Imeon inverter Inverter mode',
48+
'options': list([
49+
'smart_grid',
50+
'backup',
51+
'on_grid',
52+
'off_grid',
53+
]),
54+
}),
55+
'context': <ANY>,
56+
'entity_id': 'select.imeon_inverter_inverter_mode',
57+
'last_changed': <ANY>,
58+
'last_reported': <ANY>,
59+
'last_updated': <ANY>,
60+
'state': 'smart_grid',
61+
})
62+
# ---

0 commit comments

Comments
 (0)