Skip to content

Commit

Permalink
Merge pull request #38 from kvj/upgrade
Browse files Browse the repository at this point in the history
Upgrade project
  • Loading branch information
kvj authored Nov 23, 2024
2 parents 856fbc5 + cfcbd9d commit 0217fea
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 53 deletions.
22 changes: 12 additions & 10 deletions custom_components/openwrt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
from .constants import DOMAIN, PLATFORMS

from homeassistant.core import HomeAssistant, SupportsResponse
from homeassistant.helpers.typing import ConfigType
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers import service
from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
)
import homeassistant.helpers.config_validation as cv

import voluptuous as vol
import homeassistant.helpers.config_validation as cv
import logging

from .coordinator import new_coordinator

_LOGGER = logging.getLogger(__name__)


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

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

hass.data[DOMAIN]['devices'][entry.entry_id] = device # Backward compatibility
entry.runtime_data = device # New style

await device.coordinator.async_config_entry_first_refresh()
hass.data[DOMAIN]['devices'][entry.entry_id] = device
for p in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, p)
)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

return True


async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
for p in PLATFORMS:
await hass.config_entries.async_forward_entry_unload(entry, p)
await hass.config_entries.async_unload_platforms(entry, PLATFORMS)

entry.runtime_data = None
hass.data[DOMAIN]['devices'].pop(entry.entry_id)

return True


Expand Down
1 change: 1 addition & 0 deletions custom_components/openwrt/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
vol.Required('verify_cert', default=False): cv.boolean,
vol.Optional('port', default=0): cv.positive_int,
vol.Optional('path', default="/ubus"): cv.string,
vol.Required('interval', default=30): cv.positive_int,
vol.Required('wps', default=False): cv.boolean,
vol.Optional('wan_devices'): cv.string,
vol.Optional('wifi_devices'): cv.string,
Expand Down
7 changes: 2 additions & 5 deletions custom_components/openwrt/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, hass, config: dict, ubus: Ubus, all_devices: dict):
_LOGGER,
name='openwrt',
update_method=self.make_async_update_data(),
update_interval=timedelta(seconds=30)
update_interval=timedelta(seconds=config.get("interval", 30))
)

@property
Expand Down Expand Up @@ -187,10 +187,7 @@ async def do_file_exec(self, command: str, params, env: dict, extra: dict):
result = await self._ubus.api_call(
"file",
"exec",
if env !={}:
dict(command=command, params=params, env=env)
else:
dict(command=command, params=params)
dict(command=command, params=params, env=env) if len(env) else dict(command=command, params=params)
)
_LOGGER.debug(f"Execute result: {self._id}: {result}")
self._coordinator.hass.bus.async_fire(
Expand Down
2 changes: 1 addition & 1 deletion custom_components/openwrt/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"requirements": [],
"iot_class": "local_polling",
"config_flow": true,
"version": "0.1.0"
"version": "0.2.0"
}

1 change: 1 addition & 0 deletions custom_components/openwrt/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"verify_cert": "Verify HTTPS certificate",
"port": "Custom port ('0' to use the default one)",
"path": "Ubus endpoint URI path",
"interval": "Data fetch interval in seconds",
"wps": "WPS support",
"wan_devices": "WAN device names (comma-separated)",
"wifi_devices": "Wi-Fi device names (comma-separated)",
Expand Down
40 changes: 3 additions & 37 deletions custom_components/openwrt/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,14 @@
"verify_cert": "Verify HTTPS certificate",
"port": "Custom port ('0' to use the default one)",
"path": "Ubus endpoint URI path",
"interval": "Data fetch interval in seconds",
"wps": "WPS support",
"wan_devices": "WAN device names (comma-separated)",
"wifi_devices": "Wi-Fi device names (comma-separated)",
"mesh_devices": "Mesh device names (comma-separated)"
}
}
}
},
"services": {
"reboot": {
"name": "Reboot device"
},
"exec": {
"fields": {
"command": {
"name": "Command",
"description": "Command to execute",
"example": "wifi reload"
},
"environment": {
"name": "Environment variables",
"description": "Map of Environment variables names with values"
},
"extra": {
"name": "Extra event fields",
"description": "Arbitrary object added to the execute result event"
}
},
"name": "Execute command"
},
"init": {
"fields": {
"name": {
"name": "Name",
"description": "Service Name"
},
"action": {
"name": "Action",
"description": "Common actions supported by most services"
}
},
"name": "Managing services"
}
}
}
}

1 change: 1 addition & 0 deletions custom_components/openwrt/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"verify_cert": "Vérifier le certificat HTTPS",
"port": "Port personnalisé ('0' pour utiliser celui par défaut)",
"path": "Chemin URL du point de terminaison Ubus",
"interval": "Data fetch interval in seconds",
"wps": "Prise en charge WPS",
"wan_devices": "Noms des périphériques WAN (séparés par des virgules)",
"wifi_devices": "Noms des appareils Wi-Fi (séparés par des virgules)",
Expand Down

0 comments on commit 0217fea

Please sign in to comment.