Skip to content

Commit

Permalink
Add setup steps for new python-omnikinverter TCP source to config flow
Browse files Browse the repository at this point in the history
[robbinjanssen#134] introduces a TCP connection backend to the `python-omnikinverter`
package, whch is "lower" in overhead when gathering data from the
inverter while at the same time providing more statistics.  Entities for
these additional statistics - as well as some that are currently missing
- will be added in a separate PR.  Note that device information
(firmware, IP address and WiFi signal strength) is unavailable through
this API.

[robbinjanssen#134]: klaasnicolaas/python-omnikinverter#134
  • Loading branch information
MarijnS95 committed Apr 27, 2022
1 parent 6c870f8 commit 5323fe2
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ It has been tested and developed on the following inverters:
| Omnik | Omniksol 2000TL | JS |
| Omnik | Omniksol 2000TL2 | JSON |
| Omnik | Omniksol 2500TL | HTML |
| Omnik | Omniksol 3000TL | JS |
| Omnik | Omniksol 3000TL | TCP |
| Omnik | Omniksol 4000TL2 | JS |
| Ginlong | Solis-DLS-WiFi | JSON/HTML |
| Hosola | 1500TL | JS |
Expand Down Expand Up @@ -62,7 +62,7 @@ custom_components

[![ha_badge][ha-add-shield]][ha-add-url]

To configure the component, add it using [Home Assistant integrations][ha-add-url]. This will provide you with a configuration screen where you can first select the data source. Again, most inverters use JS. Some use JSON and in some rare cases HTML is used.
To configure the component, add it using [Home Assistant integrations][ha-add-url]. This will provide you with a configuration screen where you can first select the data source. Again, most inverters use JS. Some use JSON and in some rare cases HTML is used. The TCP backend contains additional electrical statistics but lacks information about the WiFi module.

After selecting the data source, enter a name and IP address as host and you're good to go!

Expand All @@ -84,7 +84,7 @@ The web interface has a javascript, JSON or HTML file that contains the actual v

- Most inverters have a JS file, try accessing `http://<your omnik ip address>/js/status.js` in your browser.
- Some inverters use a JSON status file to output the values. Check if your inverter outputs JSON data by navigating to: `http://<your omnik ip address>/status.json?CMD=inv_query`.
- A few inverters dont have JS or JSON but output the values directly in a HTML files. Check if your inverter supports the following URL: `http://<your omnik ip address>/status.html`. _Note that this will work for almost all inverters, but you need to check the HTML source for a `<script>` tag that contains the relevant `webData`._
- A few inverters don't have JS or JSON but output the values directly in a HTML files. Check if your inverter supports the following URL: `http://<your omnik ip address>/status.html`. _Note that this will work for almost all inverters, but you need to check the HTML source for a `<script>` tag that contains the relevant `webData`._

If none of the methods work, please open a [new issue](https://github.com/robbinjanssen/home-assistant-omnik-inverter/issues/new) and we might be able to make it work for your inverter 😄 Make sure you let us know what inverter you use.

Expand Down
7 changes: 7 additions & 0 deletions custom_components/omnik_inverter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from .const import (
CONF_SCAN_INTERVAL,
CONF_SERIAL,
CONF_SOURCE_TYPE,
CONFIGFLOW_VERSION,
DEFAULT_SCAN_INTERVAL,
Expand Down Expand Up @@ -105,6 +106,12 @@ def __init__(
username=self.config_entry.data[CONF_USERNAME],
password=self.config_entry.data[CONF_PASSWORD],
)
if self.config_entry.data[CONF_SOURCE_TYPE] == "tcp":
self.omnikinverter = OmnikInverter(
host=self.config_entry.data[CONF_HOST],
source_type=self.config_entry.data[CONF_SOURCE_TYPE],
serial_number=self.config_entry.data[CONF_SERIAL],
)
else:
self.omnikinverter = OmnikInverter(
host=self.config_entry.data[CONF_HOST],
Expand Down
45 changes: 44 additions & 1 deletion custom_components/omnik_inverter/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .const import (
CONF_SCAN_INTERVAL,
CONF_SOURCE_TYPE,
CONF_SERIAL,
CONFIGFLOW_VERSION,
DEFAULT_SCAN_INTERVAL,
DOMAIN,
Expand Down Expand Up @@ -54,9 +55,11 @@ async def async_step_user(
self.source_type = user_selection.lower()
if user_selection == "HTML":
return await self.async_step_setup_html()
elif user_selection == "TCP":
return await self.async_step_setup_tcp()
return await self.async_step_setup()

list_of_types = ["Javascript", "JSON", "HTML"]
list_of_types = ["Javascript", "JSON", "HTML", "TCP"]

schema = vol.Schema({vol.Required(CONF_TYPE): vol.In(list_of_types)})
return self.async_show_form(step_id="user", data_schema=schema, errors=errors)
Expand Down Expand Up @@ -141,6 +144,46 @@ async def async_step_setup_html(
errors=errors,
)

async def async_step_setup_tcp(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle setup flow for tcp route."""
errors = {}

if user_input is not None:
try:
async with OmnikInverter(
host=user_input[CONF_HOST],
source_type=self.source_type,
serial_number=user_input[CONF_SERIAL],
) as client:
await client.inverter()
except OmnikInverterError:
errors["base"] = "cannot_connect"
else:
return self.async_create_entry(
title=user_input[CONF_NAME],
data={
CONF_HOST: user_input[CONF_HOST],
CONF_SOURCE_TYPE: self.source_type,
CONF_SERIAL: user_input[CONF_SERIAL],
},
)

return self.async_show_form(
step_id="setup_tcp",
data_schema=vol.Schema(
{
vol.Optional(
CONF_NAME, default=self.hass.config.location_name
): str,
vol.Required(CONF_HOST): str,
vol.Required(CONF_SERIAL): int,
}
),
errors=errors,
)


class OmnikInverterOptionsFlowHandler(OptionsFlow):
"""Handle options."""
Expand Down
1 change: 1 addition & 0 deletions custom_components/omnik_inverter/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

CONF_SOURCE_TYPE = "source_type"
CONF_SCAN_INTERVAL = "scan_interval"
CONF_SERIAL = "serial"

ATTR_ENTRY_TYPE: Final = "entry_type"
ENTRY_TYPE_SERVICE: Final = "service"
Expand Down
4 changes: 2 additions & 2 deletions custom_components/omnik_inverter/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
from homeassistant.core import HomeAssistant

from . import OmnikInverterDataUpdateCoordinator
from .const import DOMAIN, SERVICE_DEVICE, SERVICE_INVERTER
from .const import CONF_SERIAL, DOMAIN, SERVICE_DEVICE, SERVICE_INVERTER

TO_REDACT = {CONF_HOST, CONF_IP_ADDRESS}
TO_REDACT = {CONF_HOST, CONF_IP_ADDRESS, CONF_SERIAL}


async def async_get_config_entry_diagnostics(
Expand Down
2 changes: 1 addition & 1 deletion custom_components/omnik_inverter/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"@robbinjanssen",
"@klaasnicolaas"
],
"requirements": ["omnikinverter==0.7.0"],
"requirements": ["git+https://github.com/MarijnS95/python-omnikinverter@tcp#omnikinverter==0.8.0"],
"iot_class": "local_polling"
}
11 changes: 10 additions & 1 deletion custom_components/omnik_inverter/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
"password": "Password"
}
},
"setup_tcp": {
"title": "Omnik Inverter - TCP",
"description": "Set up Omnik Inverter to integrate with Home Assistant.",
"data": {
"name": "Name",
"host": "Host",
"serial": "Serial Number"
}
},
"user": {
"description": "Choose which data source applies to your Omnik Inverter.",
"data": {
Expand All @@ -41,4 +50,4 @@
}
}
}
}
}
11 changes: 10 additions & 1 deletion custom_components/omnik_inverter/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
"password": "Wachtwoord"
}
},
"setup_tcp": {
"title": "Omnik Inverter - TCP",
"description": "Stel Omnik Inverter in om te integreren met Home Assistant.",
"data": {
"name": "Naam",
"host": "Host",
"serial": "Serienummer",
}
},
"user": {
"description": "Kies welke data source van toepassing is bij jouw Omnik Inverter.",
"data": {
Expand All @@ -41,4 +50,4 @@
}
}
}
}
}

0 comments on commit 5323fe2

Please sign in to comment.