Skip to content

Commit

Permalink
Merge pull request #19 from w1tw0lf/update-interval
Browse files Browse the repository at this point in the history
Allow the user to set the update interval for polling
  • Loading branch information
ingoldsby authored Feb 5, 2025
2 parents b0cd596 + aaf7b48 commit 13f0271
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
11 changes: 9 additions & 2 deletions custom_components/unifi_mqtt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
CONF_PORT,
CONF_VERIFY_SSL,
CONF_VERSION,
UPDATE_INTERVAL,
CONF_UPDATE_INTERVAL,
DEFAULT_UPDATE_INTERVAL
)

_LOGGER = logging.getLogger(__name__)
Expand All @@ -49,6 +50,7 @@ async def async_setup_entry(hass, entry):
port = entry.data[CONF_PORT]
verify_ssl = entry.data[CONF_VERIFY_SSL]
version = entry.data[CONF_VERSION]
update_interval = entry.data.get(CONF_UPDATE_INTERVAL, DEFAULT_UPDATE_INTERVAL)

def init_controller():
return Controller(
Expand All @@ -72,6 +74,11 @@ async def update_unifi_data(now):
active_devices = []

for device in unifi_devices:
# If the device is not a dictionary, log its value and skip processing it.
if not isinstance(device, dict):
_LOGGER.error("Received device that is not a dictionary: %s", device)
continue

if not device.get("adopted"):
continue

Expand Down Expand Up @@ -282,7 +289,7 @@ async def update_unifi_data(now):

global UPDATE_LISTENER
UPDATE_LISTENER = async_track_time_interval(
hass, update_unifi_data, timedelta(seconds=UPDATE_INTERVAL)
hass, update_unifi_data, timedelta(seconds=update_interval)
)
hass.async_create_task(update_unifi_data(None))

Expand Down
5 changes: 4 additions & 1 deletion custom_components/unifi_mqtt/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
CONF_PORT,
CONF_VERIFY_SSL,
CONF_VERSION,
CONF_UPDATE_INTERVAL,
VERSION_OPTIONS,
DEFAULT_SITE_ID,
DEFAULT_PORT,
DEFAULT_VERIFY_SSL,
DEFAULT_VERSION,
DEFAULT_UPDATE_INTERVAL
)

_LOGGER = logging.getLogger(__name__)
Expand All @@ -31,10 +33,11 @@
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
vol.Optional(CONF_VERIFY_SSL, default=DEFAULT_VERIFY_SSL): cv.boolean,
vol.Optional(CONF_VERSION, default=DEFAULT_VERSION): vol.In(VERSION_OPTIONS),
vol.Optional(CONF_UPDATE_INTERVAL, default=DEFAULT_UPDATE_INTERVAL): cv.positive_int,
})

class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for UniFi MQTT integration."""
"""Handle a config flow for UniFi Device Info integration."""

VERSION = 1

Expand Down
3 changes: 2 additions & 1 deletion custom_components/unifi_mqtt/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
CONF_PORT = "port"
CONF_VERIFY_SSL = "Verify SSL"
CONF_VERSION = "version"
CONF_UPDATE_INTERVAL = "Update interval"

VERSION_OPTIONS = [
"UDMP-unifiOS", # default
Expand All @@ -22,4 +23,4 @@
DEFAULT_VERIFY_SSL = False
DEFAULT_VERSION = "UDMP-unifiOS"

UPDATE_INTERVAL = 60 # seconds
DEFAULT_UPDATE_INTERVAL = 60 # seconds
2 changes: 1 addition & 1 deletion custom_components/unifi_mqtt/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"domain": "unifi_mqtt",
"name": "UniFi Device Info Integration",
"version": "1.0.0",
"version": "1.0.1",
"documentation": "https://github.com/w1tw0lf/Unifi-Device-info",
"dependencies": [
"mqtt"
Expand Down

0 comments on commit 13f0271

Please sign in to comment.