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 e30676a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 6 additions & 3 deletions custom_components/econnect_metronet/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,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("experimental", {})
self._attr_force_update = experimental.get("force_update", False)

super().__init__(coordinator)
self.entity_id = generate_entity_id(config, name)
Expand Down Expand Up @@ -117,7 +118,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("experimental", {})
self._attr_force_update = experimental.get("force_update", False)

super().__init__(coordinator)
self.entity_id = generate_entity_id(config, name)
Expand Down Expand Up @@ -163,7 +165,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("experimental", {})
self._attr_force_update = experimental.get("force_update", False)

super().__init__(coordinator)
self.entity_id = generate_entity_id(config, name)
Expand Down
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 e30676a

Please sign in to comment.