Skip to content

Commit 0217fea

Browse files
authored
Merge pull request #38 from kvj/upgrade
Upgrade project
2 parents 856fbc5 + cfcbd9d commit 0217fea

File tree

7 files changed

+21
-53
lines changed

7 files changed

+21
-53
lines changed

custom_components/openwrt/__init__.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
from .constants import DOMAIN, PLATFORMS
33

44
from homeassistant.core import HomeAssistant, SupportsResponse
5-
from homeassistant.helpers.typing import ConfigType
5+
from homeassistant.config_entries import ConfigEntry
66
from homeassistant.helpers import service
7+
from homeassistant.helpers.typing import ConfigType
78
from homeassistant.helpers.update_coordinator import (
89
CoordinatorEntity,
910
)
11+
import homeassistant.helpers.config_validation as cv
1012

1113
import voluptuous as vol
12-
import homeassistant.helpers.config_validation as cv
1314
import logging
1415

1516
from .coordinator import new_coordinator
1617

1718
_LOGGER = logging.getLogger(__name__)
1819

19-
2020
CONFIG_SCHEMA = vol.Schema({
2121
DOMAIN: vol.Schema({
2222
}),
@@ -28,19 +28,21 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
2828

2929
device = new_coordinator(hass, data, hass.data[DOMAIN]['devices'])
3030

31+
hass.data[DOMAIN]['devices'][entry.entry_id] = device # Backward compatibility
32+
entry.runtime_data = device # New style
33+
3134
await device.coordinator.async_config_entry_first_refresh()
32-
hass.data[DOMAIN]['devices'][entry.entry_id] = device
33-
for p in PLATFORMS:
34-
hass.async_create_task(
35-
hass.config_entries.async_forward_entry_setup(entry, p)
36-
)
35+
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
36+
3737
return True
3838

3939

4040
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
41-
for p in PLATFORMS:
42-
await hass.config_entries.async_forward_entry_unload(entry, p)
41+
await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
42+
43+
entry.runtime_data = None
4344
hass.data[DOMAIN]['devices'].pop(entry.entry_id)
45+
4446
return True
4547

4648

custom_components/openwrt/config_flow.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
vol.Required('verify_cert', default=False): cv.boolean,
1818
vol.Optional('port', default=0): cv.positive_int,
1919
vol.Optional('path', default="/ubus"): cv.string,
20+
vol.Required('interval', default=30): cv.positive_int,
2021
vol.Required('wps', default=False): cv.boolean,
2122
vol.Optional('wan_devices'): cv.string,
2223
vol.Optional('wifi_devices'): cv.string,

custom_components/openwrt/coordinator.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(self, hass, config: dict, ubus: Ubus, all_devices: dict):
3030
_LOGGER,
3131
name='openwrt',
3232
update_method=self.make_async_update_data(),
33-
update_interval=timedelta(seconds=30)
33+
update_interval=timedelta(seconds=config.get("interval", 30))
3434
)
3535

3636
@property
@@ -187,10 +187,7 @@ async def do_file_exec(self, command: str, params, env: dict, extra: dict):
187187
result = await self._ubus.api_call(
188188
"file",
189189
"exec",
190-
if env !={}:
191-
dict(command=command, params=params, env=env)
192-
else:
193-
dict(command=command, params=params)
190+
dict(command=command, params=params, env=env) if len(env) else dict(command=command, params=params)
194191
)
195192
_LOGGER.debug(f"Execute result: {self._id}: {result}")
196193
self._coordinator.hass.bus.async_fire(

custom_components/openwrt/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"requirements": [],
99
"iot_class": "local_polling",
1010
"config_flow": true,
11-
"version": "0.1.0"
11+
"version": "0.2.0"
1212
}
1313

custom_components/openwrt/strings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"verify_cert": "Verify HTTPS certificate",
1414
"port": "Custom port ('0' to use the default one)",
1515
"path": "Ubus endpoint URI path",
16+
"interval": "Data fetch interval in seconds",
1617
"wps": "WPS support",
1718
"wan_devices": "WAN device names (comma-separated)",
1819
"wifi_devices": "Wi-Fi device names (comma-separated)",

custom_components/openwrt/translations/en.json

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,14 @@
1313
"verify_cert": "Verify HTTPS certificate",
1414
"port": "Custom port ('0' to use the default one)",
1515
"path": "Ubus endpoint URI path",
16+
"interval": "Data fetch interval in seconds",
1617
"wps": "WPS support",
1718
"wan_devices": "WAN device names (comma-separated)",
1819
"wifi_devices": "Wi-Fi device names (comma-separated)",
1920
"mesh_devices": "Mesh device names (comma-separated)"
2021
}
2122
}
2223
}
23-
},
24-
"services": {
25-
"reboot": {
26-
"name": "Reboot device"
27-
},
28-
"exec": {
29-
"fields": {
30-
"command": {
31-
"name": "Command",
32-
"description": "Command to execute",
33-
"example": "wifi reload"
34-
},
35-
"environment": {
36-
"name": "Environment variables",
37-
"description": "Map of Environment variables names with values"
38-
},
39-
"extra": {
40-
"name": "Extra event fields",
41-
"description": "Arbitrary object added to the execute result event"
42-
}
43-
},
44-
"name": "Execute command"
45-
},
46-
"init": {
47-
"fields": {
48-
"name": {
49-
"name": "Name",
50-
"description": "Service Name"
51-
},
52-
"action": {
53-
"name": "Action",
54-
"description": "Common actions supported by most services"
55-
}
56-
},
57-
"name": "Managing services"
58-
}
5924
}
60-
}
25+
}
26+

custom_components/openwrt/translations/fr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"verify_cert": "Vérifier le certificat HTTPS",
1414
"port": "Port personnalisé ('0' pour utiliser celui par défaut)",
1515
"path": "Chemin URL du point de terminaison Ubus",
16+
"interval": "Data fetch interval in seconds",
1617
"wps": "Prise en charge WPS",
1718
"wan_devices": "Noms des périphériques WAN (séparés par des virgules)",
1819
"wifi_devices": "Noms des appareils Wi-Fi (séparés par des virgules)",

0 commit comments

Comments
 (0)