mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Goodwe TCP support (port 502) (#147900)
This commit is contained in:
parent
5c4f166f6f
commit
9d2ffa6372
@ -1,6 +1,7 @@
|
||||
"""The Goodwe inverter component."""
|
||||
|
||||
from goodwe import InverterError, connect
|
||||
from goodwe.const import GOODWE_TCP_PORT, GOODWE_UDP_PORT
|
||||
|
||||
from homeassistant.const import CONF_HOST
|
||||
from homeassistant.core import HomeAssistant
|
||||
@ -20,11 +21,22 @@ async def async_setup_entry(hass: HomeAssistant, entry: GoodweConfigEntry) -> bo
|
||||
try:
|
||||
inverter = await connect(
|
||||
host=host,
|
||||
port=GOODWE_UDP_PORT,
|
||||
family=model_family,
|
||||
retries=10,
|
||||
)
|
||||
except InverterError as err:
|
||||
raise ConfigEntryNotReady from err
|
||||
except InverterError as err_udp:
|
||||
# First try with UDP failed, trying with the TCP port
|
||||
try:
|
||||
inverter = await connect(
|
||||
host=host,
|
||||
port=GOODWE_TCP_PORT,
|
||||
family=model_family,
|
||||
retries=10,
|
||||
)
|
||||
except InverterError:
|
||||
# Both ports are unavailable
|
||||
raise ConfigEntryNotReady from err_udp
|
||||
|
||||
device_info = DeviceInfo(
|
||||
configuration_url="https://www.semsportal.com",
|
||||
|
@ -6,6 +6,7 @@ import logging
|
||||
from typing import Any
|
||||
|
||||
from goodwe import InverterError, connect
|
||||
from goodwe.const import GOODWE_TCP_PORT, GOODWE_UDP_PORT
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
||||
@ -27,6 +28,18 @@ class GoodweFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
VERSION = 1
|
||||
|
||||
async def _handle_successful_connection(self, inverter, host):
|
||||
await self.async_set_unique_id(inverter.serial_number)
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
return self.async_create_entry(
|
||||
title=DEFAULT_NAME,
|
||||
data={
|
||||
CONF_HOST: host,
|
||||
CONF_MODEL_FAMILY: type(inverter).__name__,
|
||||
},
|
||||
)
|
||||
|
||||
async def async_step_user(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
@ -34,22 +47,19 @@ class GoodweFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
errors = {}
|
||||
if user_input is not None:
|
||||
host = user_input[CONF_HOST]
|
||||
|
||||
try:
|
||||
inverter = await connect(host=host, retries=10)
|
||||
inverter = await connect(host=host, port=GOODWE_UDP_PORT, retries=10)
|
||||
except InverterError:
|
||||
errors[CONF_HOST] = "connection_error"
|
||||
try:
|
||||
inverter = await connect(
|
||||
host=host, port=GOODWE_TCP_PORT, retries=10
|
||||
)
|
||||
except InverterError:
|
||||
errors[CONF_HOST] = "connection_error"
|
||||
else:
|
||||
return await self._handle_successful_connection(inverter, host)
|
||||
else:
|
||||
await self.async_set_unique_id(inverter.serial_number)
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
return self.async_create_entry(
|
||||
title=DEFAULT_NAME,
|
||||
data={
|
||||
CONF_HOST: host,
|
||||
CONF_MODEL_FAMILY: type(inverter).__name__,
|
||||
},
|
||||
)
|
||||
return await self._handle_successful_connection(inverter, host)
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="user", data_schema=CONFIG_SCHEMA, errors=errors
|
||||
|
@ -6,5 +6,5 @@
|
||||
"documentation": "https://www.home-assistant.io/integrations/goodwe",
|
||||
"iot_class": "local_polling",
|
||||
"loggers": ["goodwe"],
|
||||
"requirements": ["goodwe==0.3.6"]
|
||||
"requirements": ["goodwe==0.4.8"]
|
||||
}
|
||||
|
@ -54,17 +54,24 @@ async def async_setup_entry(
|
||||
# Inverter model does not support this setting
|
||||
_LOGGER.debug("Could not read inverter operation mode")
|
||||
else:
|
||||
async_add_entities(
|
||||
[
|
||||
InverterOperationModeEntity(
|
||||
device_info,
|
||||
OPERATION_MODE,
|
||||
inverter,
|
||||
[v for k, v in _MODE_TO_OPTION.items() if k in supported_modes],
|
||||
_MODE_TO_OPTION[active_mode],
|
||||
)
|
||||
]
|
||||
)
|
||||
active_mode_option = _MODE_TO_OPTION.get(active_mode)
|
||||
if active_mode_option is not None:
|
||||
async_add_entities(
|
||||
[
|
||||
InverterOperationModeEntity(
|
||||
device_info,
|
||||
OPERATION_MODE,
|
||||
inverter,
|
||||
[v for k, v in _MODE_TO_OPTION.items() if k in supported_modes],
|
||||
active_mode_option,
|
||||
)
|
||||
]
|
||||
)
|
||||
else:
|
||||
_LOGGER.warning(
|
||||
"Active mode %s not found in Goodwe Inverter Operation Mode Entity. Skipping entity creation",
|
||||
active_mode,
|
||||
)
|
||||
|
||||
|
||||
class InverterOperationModeEntity(SelectEntity):
|
||||
|
2
requirements_all.txt
generated
2
requirements_all.txt
generated
@ -1035,7 +1035,7 @@ go2rtc-client==0.2.1
|
||||
goalzero==0.2.2
|
||||
|
||||
# homeassistant.components.goodwe
|
||||
goodwe==0.3.6
|
||||
goodwe==0.4.8
|
||||
|
||||
# homeassistant.components.google_mail
|
||||
# homeassistant.components.google_tasks
|
||||
|
2
requirements_test_all.txt
generated
2
requirements_test_all.txt
generated
@ -902,7 +902,7 @@ go2rtc-client==0.2.1
|
||||
goalzero==0.2.2
|
||||
|
||||
# homeassistant.components.goodwe
|
||||
goodwe==0.3.6
|
||||
goodwe==0.4.8
|
||||
|
||||
# homeassistant.components.google_mail
|
||||
# homeassistant.components.google_tasks
|
||||
|
Loading…
x
Reference in New Issue
Block a user