mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Add support for 4 MPTT inverter (#86901)
This commit is contained in:
parent
b0146618cb
commit
ea94a2fbfd
@ -46,7 +46,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
name=entry.title,
|
||||
manufacturer="GoodWe",
|
||||
model=inverter.model_name,
|
||||
sw_version=f"{inverter.software_version} ({inverter.arm_version})",
|
||||
sw_version=f"{inverter.firmware} / {inverter.arm_firmware}",
|
||||
)
|
||||
|
||||
async def async_update_data():
|
||||
|
@ -6,5 +6,5 @@
|
||||
"documentation": "https://www.home-assistant.io/integrations/goodwe",
|
||||
"iot_class": "local_polling",
|
||||
"loggers": ["goodwe"],
|
||||
"requirements": ["goodwe==0.2.18"]
|
||||
"requirements": ["goodwe==0.2.25"]
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""GoodWe PV inverter selection settings entities."""
|
||||
import logging
|
||||
|
||||
from goodwe import Inverter, InverterError
|
||||
from goodwe import Inverter, InverterError, OperationMode
|
||||
|
||||
from homeassistant.components.select import SelectEntity, SelectEntityDescription
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
@ -15,17 +15,26 @@ from .const import DOMAIN, KEY_DEVICE_INFO, KEY_INVERTER
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
_MODE_TO_OPTION: dict[OperationMode, str] = {
|
||||
OperationMode.GENERAL: "general",
|
||||
OperationMode.OFF_GRID: "off_grid",
|
||||
OperationMode.BACKUP: "backup",
|
||||
OperationMode.ECO: "eco",
|
||||
OperationMode.PEAK_SHAVING: "peak_shaving",
|
||||
OperationMode.ECO_CHARGE: "eco_charge",
|
||||
OperationMode.ECO_DISCHARGE: "eco_discharge",
|
||||
}
|
||||
|
||||
_OPTION_TO_MODE: dict[str, OperationMode] = {
|
||||
value: key for key, value in _MODE_TO_OPTION.items()
|
||||
}
|
||||
|
||||
OPERATION_MODE = SelectEntityDescription(
|
||||
key="operation_mode",
|
||||
name="Inverter operation mode",
|
||||
icon="mdi:solar-power",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
options=[
|
||||
"General mode",
|
||||
"Off grid mode",
|
||||
"Backup mode",
|
||||
"Eco mode",
|
||||
],
|
||||
translation_key="operation_mode",
|
||||
)
|
||||
|
||||
|
||||
@ -38,6 +47,7 @@ async def async_setup_entry(
|
||||
inverter = hass.data[DOMAIN][config_entry.entry_id][KEY_INVERTER]
|
||||
device_info = hass.data[DOMAIN][config_entry.entry_id][KEY_DEVICE_INFO]
|
||||
|
||||
supported_modes = await inverter.get_operation_modes(False)
|
||||
# read current operating mode from the inverter
|
||||
try:
|
||||
active_mode = await inverter.get_operation_mode()
|
||||
@ -45,14 +55,14 @@ async def async_setup_entry(
|
||||
# Inverter model does not support this setting
|
||||
_LOGGER.debug("Could not read inverter operation mode")
|
||||
else:
|
||||
if (options := OPERATION_MODE.options) and 0 <= active_mode < len(options):
|
||||
async_add_entities(
|
||||
[
|
||||
InverterOperationModeEntity(
|
||||
device_info,
|
||||
OPERATION_MODE,
|
||||
inverter,
|
||||
options[active_mode],
|
||||
[v for k, v in _MODE_TO_OPTION.items() if k in supported_modes],
|
||||
_MODE_TO_OPTION[active_mode],
|
||||
)
|
||||
]
|
||||
)
|
||||
@ -68,17 +78,19 @@ class InverterOperationModeEntity(SelectEntity):
|
||||
device_info: DeviceInfo,
|
||||
description: SelectEntityDescription,
|
||||
inverter: Inverter,
|
||||
supported_options: list[str],
|
||||
current_mode: str,
|
||||
) -> None:
|
||||
"""Initialize the inverter operation mode setting entity."""
|
||||
self.entity_description = description
|
||||
self._attr_unique_id = f"{DOMAIN}-{description.key}-{inverter.serial_number}"
|
||||
self._attr_device_info = device_info
|
||||
self._attr_options = supported_options
|
||||
self._attr_current_option = current_mode
|
||||
self._inverter: Inverter = inverter
|
||||
|
||||
async def async_select_option(self, option: str) -> None:
|
||||
"""Change the selected option."""
|
||||
await self._inverter.set_operation_mode(self.options.index(option))
|
||||
await self._inverter.set_operation_mode(_OPTION_TO_MODE[option])
|
||||
self._attr_current_option = option
|
||||
self.async_write_ha_state()
|
||||
|
@ -16,5 +16,20 @@
|
||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
|
||||
"already_in_progress": "[%key:common::config_flow::abort::already_in_progress%]"
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"select": {
|
||||
"operation_mode": {
|
||||
"state": {
|
||||
"general": "General mode",
|
||||
"off_grid": "Off grid mode",
|
||||
"backup": "Backup mode",
|
||||
"eco": "Eco mode",
|
||||
"peak_shaving": "Peak shaving mode",
|
||||
"eco_charge": "Eco charge mode",
|
||||
"eco_discharge": "Eco discharge mode"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -798,7 +798,7 @@ glances_api==0.4.1
|
||||
goalzero==0.2.1
|
||||
|
||||
# homeassistant.components.goodwe
|
||||
goodwe==0.2.18
|
||||
goodwe==0.2.25
|
||||
|
||||
# homeassistant.components.google_mail
|
||||
google-api-python-client==2.71.0
|
||||
|
@ -611,7 +611,7 @@ glances_api==0.4.1
|
||||
goalzero==0.2.1
|
||||
|
||||
# homeassistant.components.goodwe
|
||||
goodwe==0.2.18
|
||||
goodwe==0.2.25
|
||||
|
||||
# homeassistant.components.google_mail
|
||||
google-api-python-client==2.71.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user