Skip to content

Commit

Permalink
Port config field
Browse files Browse the repository at this point in the history
  • Loading branch information
pNre committed Aug 28, 2023
1 parent fd32d1d commit b65baf2
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
13 changes: 13 additions & 0 deletions custom_components/ksenia_lares/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,16 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
hass.data[DOMAIN].pop(entry.entry_id)

return unload_ok


async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry):
"""Migrate old entry."""

if config_entry.version == 1:
new = {**config_entry.data}
new["port"] = 4202

config_entry.version = 2
hass.config_entries.async_update_entry(config_entry, data=new)

return True
5 changes: 3 additions & 2 deletions custom_components/ksenia_lares/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ def __init__(self, data: dict) -> None:
username = data["username"]
password = data["password"]
host = data["host"]
port = data["port"]

self._auth = aiohttp.BasicAuth(username, password)
self._ip = host
self._port = 4202
self._port = port
self._host = f"http://{host}:{self._port}"
self._zone_descriptions = None
self._partition_descriptions = None
Expand Down Expand Up @@ -112,7 +113,7 @@ async def partition_descriptions(self):

return self._partition_descriptions

async def paritions(self):
async def partitions(self):
"""Get status of partitions"""
response = await self.get("partitions/partitionsStatus48IP.xml")

Expand Down
4 changes: 2 additions & 2 deletions custom_components/ksenia_lares/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
STEP_USER_DATA_SCHEMA = vol.Schema(
{
vol.Required("host"): str,
vol.Required("port", default=4202): int,
vol.Required("username"): str,
vol.Required("password"): str,
}
Expand All @@ -56,7 +57,7 @@ async def validate_input(hass: HomeAssistant, data):
class LaresConfigFlow(ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Ksenia Lares Alarm."""

VERSION = 1
VERSION = 2

@staticmethod
@callback
Expand Down Expand Up @@ -95,7 +96,6 @@ async def async_step_user(self, user_input=None):
step_id="user", data_schema=STEP_USER_DATA_SCHEMA, errors=errors
)


class LaresOptionsFlowHandler(OptionsFlow):
"""Handle a options flow for Ksenia Lares Alarm."""

Expand Down
2 changes: 1 addition & 1 deletion custom_components/ksenia_lares/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ async def _async_update_data(self) -> dict:
"""Fetch data from Ksenia Lares client."""
async with async_timeout.timeout(DEFAULT_TIMEOUT):
zones = await self.client.zones()
partitions = await self.client.paritions()
partitions = await self.client.partitions()

return {DATA_ZONES: zones, DATA_PARTITIONS: partitions}
3 changes: 2 additions & 1 deletion custom_components/ksenia_lares/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"user": {
"data": {
"host": "[%key:common::config_flow::data::host%]",
"port": "[%key:common::config_flow::data::port%]",
"username": "[%key:common::config_flow::data::username%]",
"password": "[%key:common::config_flow::data::password%]"
}
Expand All @@ -24,7 +25,7 @@
"description": "Link different alarm states to partition and scenarios.",
"data": {
"scenario_disarm": "Disarm scenario",
"partition_away": "Away paritions",
"partition_away": "Away partitions",
"scenario_away": "Away scenario",
"partition_home": "Home partitions",
"scenario_home": "Home scenario",
Expand Down
3 changes: 2 additions & 1 deletion custom_components/ksenia_lares/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"user": {
"data": {
"host": "Host",
"port": "Port",
"password": "Password",
"username": "Username"
}
Expand All @@ -24,7 +25,7 @@
"description": "Link partitions to states, the state will be set when the selected partitions are armed",
"data": {
"scenario_disarm": "Disarm scenario",
"partition_away": "Away paritions",
"partition_away": "Away partitions",
"scenario_away": "Away scenario",
"partition_home": "Home partitions",
"scenario_home": "Home scenario",
Expand Down

0 comments on commit b65baf2

Please sign in to comment.