Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(experimental): namespace experimental settings under experimental key #86

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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