Skip to content

Commit

Permalink
fix(experimental): namespace experimental settings under `experimenta…
Browse files Browse the repository at this point in the history
…l` key
  • Loading branch information
palazzem committed Oct 18, 2023
1 parent 7aaeb37 commit 7df96a4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
17 changes: 13 additions & 4 deletions custom_components/econnect_metronet/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
DataUpdateCoordinator,
)

from .const import DOMAIN, KEY_COORDINATOR, KEY_DEVICE
from .const import (
CONF_EXPERIMENTAL,
CONF_FORCE_UPDATE,
DOMAIN,
KEY_COORDINATOR,
KEY_DEVICE,
)
from .devices import AlarmDevice
from .helpers import generate_entity_id

Expand Down Expand Up @@ -62,7 +68,8 @@ def __init__(
) -> None:
"""Construct."""
# Enable experimental settings from the configuration file
self._attr_force_update = coordinator.hass.data[DOMAIN].get("force_update", False)
experimental = coordinator.hass.data[DOMAIN].get(CONF_EXPERIMENTAL, {})
self._attr_force_update = experimental.get(CONF_FORCE_UPDATE, False)

super().__init__(coordinator)
self.entity_id = generate_entity_id(config, name)
Expand Down Expand Up @@ -117,7 +124,8 @@ def __init__(
) -> None:
"""Construct."""
# Enable experimental settings from the configuration file
self._attr_force_update = coordinator.hass.data[DOMAIN].get("force_update", False)
experimental = coordinator.hass.data[DOMAIN].get(CONF_EXPERIMENTAL, {})
self._attr_force_update = experimental.get(CONF_FORCE_UPDATE, False)

super().__init__(coordinator)
self.entity_id = generate_entity_id(config, name)
Expand Down Expand Up @@ -163,7 +171,8 @@ def __init__(
) -> None:
"""Construct."""
# Enable experimental settings from the configuration file
self._attr_force_update = coordinator.hass.data[DOMAIN].get("force_update", False)
experimental = coordinator.hass.data[DOMAIN].get(CONF_EXPERIMENTAL, {})
self._attr_force_update = experimental.get(CONF_FORCE_UPDATE, False)

super().__init__(coordinator)
self.entity_id = generate_entity_id(config, name)
Expand Down
4 changes: 4 additions & 0 deletions custom_components/econnect_metronet/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@
# Fast scanning is required for real-time updates of the alarm state.
SCAN_INTERVAL_DEFAULT = 5
POLLING_TIMEOUT = 20

# Experimental Settings
CONF_EXPERIMENTAL = "experimental"
CONF_FORCE_UPDATE = "force_update"
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
from custom_components.econnect_metronet.const import DOMAIN


class TestExperiments:
class TestExperimentalSettings:
def test_sensor_force_update_default(self, coordinator, config_entry, alarm_device):
# Ensure the default is to not force any update
entity = AlertSensor("device_tamper", 7, config_entry, "device_tamper", coordinator, alarm_device)
assert entity._attr_force_update is False

def test_sensor_force_update_on(self, hass, coordinator, config_entry, alarm_device):
# Ensure you can force the entity update
hass.data[DOMAIN] = {"force_update": True}
hass.data[DOMAIN] = {
"experimental": {
"force_update": True,
}
}
entity = AlertSensor("device_tamper", 7, config_entry, "device_tamper", coordinator, alarm_device)
assert entity._attr_force_update is True

0 comments on commit 7df96a4

Please sign in to comment.