Skip to content

Commit

Permalink
Make refresh interval configurable #35
Browse files Browse the repository at this point in the history
  • Loading branch information
kvj committed Nov 23, 2024
1 parent ac4f65a commit cfcbd9d
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 42 deletions.
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
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 cfcbd9d

Please sign in to comment.