mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +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."""
|
"""The Goodwe inverter component."""
|
||||||
|
|
||||||
from goodwe import InverterError, connect
|
from goodwe import InverterError, connect
|
||||||
|
from goodwe.const import GOODWE_TCP_PORT, GOODWE_UDP_PORT
|
||||||
|
|
||||||
from homeassistant.const import CONF_HOST
|
from homeassistant.const import CONF_HOST
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -20,11 +21,22 @@ async def async_setup_entry(hass: HomeAssistant, entry: GoodweConfigEntry) -> bo
|
|||||||
try:
|
try:
|
||||||
inverter = await connect(
|
inverter = await connect(
|
||||||
host=host,
|
host=host,
|
||||||
|
port=GOODWE_UDP_PORT,
|
||||||
family=model_family,
|
family=model_family,
|
||||||
retries=10,
|
retries=10,
|
||||||
)
|
)
|
||||||
except InverterError as err:
|
except InverterError as err_udp:
|
||||||
raise ConfigEntryNotReady from err
|
# 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(
|
device_info = DeviceInfo(
|
||||||
configuration_url="https://www.semsportal.com",
|
configuration_url="https://www.semsportal.com",
|
||||||
|
@ -6,6 +6,7 @@ import logging
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from goodwe import InverterError, connect
|
from goodwe import InverterError, connect
|
||||||
|
from goodwe.const import GOODWE_TCP_PORT, GOODWE_UDP_PORT
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
||||||
@ -27,19 +28,7 @@ class GoodweFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
async def async_step_user(
|
async def _handle_successful_connection(self, inverter, host):
|
||||||
self, user_input: dict[str, Any] | None = None
|
|
||||||
) -> ConfigFlowResult:
|
|
||||||
"""Handle a flow initialized by the user."""
|
|
||||||
errors = {}
|
|
||||||
if user_input is not None:
|
|
||||||
host = user_input[CONF_HOST]
|
|
||||||
|
|
||||||
try:
|
|
||||||
inverter = await connect(host=host, retries=10)
|
|
||||||
except InverterError:
|
|
||||||
errors[CONF_HOST] = "connection_error"
|
|
||||||
else:
|
|
||||||
await self.async_set_unique_id(inverter.serial_number)
|
await self.async_set_unique_id(inverter.serial_number)
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
|
|
||||||
@ -51,6 +40,27 @@ class GoodweFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def async_step_user(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> ConfigFlowResult:
|
||||||
|
"""Handle a flow initialized by the user."""
|
||||||
|
errors = {}
|
||||||
|
if user_input is not None:
|
||||||
|
host = user_input[CONF_HOST]
|
||||||
|
try:
|
||||||
|
inverter = await connect(host=host, port=GOODWE_UDP_PORT, retries=10)
|
||||||
|
except InverterError:
|
||||||
|
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:
|
||||||
|
return await self._handle_successful_connection(inverter, host)
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user", data_schema=CONFIG_SCHEMA, errors=errors
|
step_id="user", data_schema=CONFIG_SCHEMA, errors=errors
|
||||||
)
|
)
|
||||||
|
@ -6,5 +6,5 @@
|
|||||||
"documentation": "https://www.home-assistant.io/integrations/goodwe",
|
"documentation": "https://www.home-assistant.io/integrations/goodwe",
|
||||||
"iot_class": "local_polling",
|
"iot_class": "local_polling",
|
||||||
"loggers": ["goodwe"],
|
"loggers": ["goodwe"],
|
||||||
"requirements": ["goodwe==0.3.6"]
|
"requirements": ["goodwe==0.4.8"]
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,8 @@ async def async_setup_entry(
|
|||||||
# Inverter model does not support this setting
|
# Inverter model does not support this setting
|
||||||
_LOGGER.debug("Could not read inverter operation mode")
|
_LOGGER.debug("Could not read inverter operation mode")
|
||||||
else:
|
else:
|
||||||
|
active_mode_option = _MODE_TO_OPTION.get(active_mode)
|
||||||
|
if active_mode_option is not None:
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
InverterOperationModeEntity(
|
InverterOperationModeEntity(
|
||||||
@ -61,10 +63,15 @@ async def async_setup_entry(
|
|||||||
OPERATION_MODE,
|
OPERATION_MODE,
|
||||||
inverter,
|
inverter,
|
||||||
[v for k, v in _MODE_TO_OPTION.items() if k in supported_modes],
|
[v for k, v in _MODE_TO_OPTION.items() if k in supported_modes],
|
||||||
_MODE_TO_OPTION[active_mode],
|
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):
|
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
|
goalzero==0.2.2
|
||||||
|
|
||||||
# homeassistant.components.goodwe
|
# homeassistant.components.goodwe
|
||||||
goodwe==0.3.6
|
goodwe==0.4.8
|
||||||
|
|
||||||
# homeassistant.components.google_mail
|
# homeassistant.components.google_mail
|
||||||
# homeassistant.components.google_tasks
|
# 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
|
goalzero==0.2.2
|
||||||
|
|
||||||
# homeassistant.components.goodwe
|
# homeassistant.components.goodwe
|
||||||
goodwe==0.3.6
|
goodwe==0.4.8
|
||||||
|
|
||||||
# homeassistant.components.google_mail
|
# homeassistant.components.google_mail
|
||||||
# homeassistant.components.google_tasks
|
# homeassistant.components.google_tasks
|
||||||
|
Loading…
x
Reference in New Issue
Block a user