Skip to content

Commit

Permalink
Configurable refresh intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-r committed Oct 24, 2024
1 parent d319a1d commit d68005c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
16 changes: 14 additions & 2 deletions custom_components/ohme/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import voluptuous as vol
from homeassistant.config_entries import (ConfigFlow, OptionsFlow)
from .const import DOMAIN, CONFIG_VERSION
from .const import DOMAIN, CONFIG_VERSION, DEFAULT_INTERVAL_CHARGESESSIONS, DEFAULT_INTERVAL_ACCOUNTINFO, DEFAULT_INTERVAL_ADVANCED, DEFAULT_INTERVAL_SCHEDULES
from .api_client import OhmeApiClient


Expand Down Expand Up @@ -89,6 +89,18 @@ async def async_step_init(self, options):
) : bool,
vol.Required(
"never_collapse_slots", default=self._config_entry.options.get("never_collapse_slots", False)
) : bool
) : bool,
vol.Required(
"interval_chargesessions", default=self._config_entry.options.get("interval_chargesessions", DEFAULT_INTERVAL_CHARGESESSIONS)
) : vol.All(vol.Coerce(float), vol.Clamp(min=DEFAULT_INTERVAL_CHARGESESSIONS)),
vol.Required(
"interval_accountinfo", default=self._config_entry.options.get("interval_accountinfo", DEFAULT_INTERVAL_ACCOUNTINFO)
) : vol.All(vol.Coerce(float), vol.Clamp(min=DEFAULT_INTERVAL_ACCOUNTINFO)),
vol.Required(
"interval_advanced", default=self._config_entry.options.get("interval_advanced", DEFAULT_INTERVAL_ADVANCED)
) : vol.All(vol.Coerce(float), vol.Clamp(min=DEFAULT_INTERVAL_ADVANCED)),
vol.Required(
"interval_schedules", default=self._config_entry.options.get("interval_schedules", DEFAULT_INTERVAL_SCHEDULES)
) : vol.All(vol.Coerce(float), vol.Clamp(min=DEFAULT_INTERVAL_SCHEDULES))
}), errors=errors
)
5 changes: 5 additions & 0 deletions custom_components/ohme/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@
COORDINATOR_ACCOUNTINFO = 1
COORDINATOR_ADVANCED = 2
COORDINATOR_SCHEDULES = 3

DEFAULT_INTERVAL_CHARGESESSIONS = 0.5
DEFAULT_INTERVAL_ACCOUNTINFO = 1
DEFAULT_INTERVAL_ADVANCED = 1
DEFAULT_INTERVAL_SCHEDULES = 10
20 changes: 14 additions & 6 deletions custom_components/ohme/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
UpdateFailed
)

from .const import DOMAIN, DATA_CLIENT
from .const import DOMAIN, DATA_CLIENT, DEFAULT_INTERVAL_CHARGESESSIONS, DEFAULT_INTERVAL_ACCOUNTINFO, DEFAULT_INTERVAL_ADVANCED, DEFAULT_INTERVAL_SCHEDULES
from .utils import get_option

_LOGGER = logging.getLogger(__name__)

Expand All @@ -20,7 +21,9 @@ def __init__(self, hass):
hass,
_LOGGER,
name="Ohme Charge Sessions",
update_interval=timedelta(seconds=30),
update_interval=timedelta(minutes=
get_option(hass, "interval_chargesessions", DEFAULT_INTERVAL_CHARGESESSIONS)
),
)
self._client = hass.data[DOMAIN][DATA_CLIENT]

Expand All @@ -42,7 +45,9 @@ def __init__(self, hass):
hass,
_LOGGER,
name="Ohme Account Info",
update_interval=timedelta(minutes=1),
update_interval=timedelta(minutes=
get_option(hass, "interval_accountinfo", DEFAULT_INTERVAL_ACCOUNTINFO)
),
)
self._client = hass.data[DOMAIN][DATA_CLIENT]

Expand All @@ -64,7 +69,9 @@ def __init__(self, hass):
hass,
_LOGGER,
name="Ohme Advanced Settings",
update_interval=timedelta(minutes=1),
update_interval=timedelta(minutes=
get_option(hass, "interval_advanced", DEFAULT_INTERVAL_ADVANCED)
),
)
self._client = hass.data[DOMAIN][DATA_CLIENT]

Expand All @@ -86,7 +93,9 @@ def __init__(self, hass):
hass,
_LOGGER,
name="Ohme Charge Schedules",
update_interval=timedelta(minutes=10),
update_interval=timedelta(minutes=
get_option(hass, "interval_schedules", DEFAULT_INTERVAL_SCHEDULES)
),
)
self._client = hass.data[DOMAIN][DATA_CLIENT]

Expand All @@ -97,4 +106,3 @@ async def _async_update_data(self):

except BaseException:
raise UpdateFailed("Error communicating with API")

9 changes: 7 additions & 2 deletions custom_components/ohme/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@
"email": "Email address",
"password": "Password",
"never_session_specific": "Never update an ongoing session",
"never_collapse_slots": "Don't collapse charge slots"
"never_collapse_slots": "Don't collapse charge slots",
"interval_chargesessions": "Charge sessions refresh rate (minutes)",
"interval_accountinfo": "Account info refresh rate (minutes)",
"interval_advanced": "Advanced settings refresh rate (minutes)",
"interval_schedules": "Schedules refresh rate (minutes)"
},
"data_description": {
"password": "If you are not changing your credentials, leave the password field empty.",
"never_session_specific": "When adjusting charge percentage, charge target or preconditioning settings, the schedule will always be updated even if a charge session is in progress.",
"never_collapse_slots": "By default, adjacent slots are merged into one. This option shows every slot, as shown in the Ohme app."
"never_collapse_slots": "By default, adjacent slots are merged into one. This option shows every slot, as shown in the Ohme app.",
"interval_schedules": "Details on which entities are updated by each coordinator are in the README."
}
}
},
Expand Down

0 comments on commit d68005c

Please sign in to comment.