Skip to content

Commit

Permalink
Cleanup, add DOOR and GARAGE to contact sensors and fixed mode detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexwijn committed May 9, 2023
1 parent 4d28315 commit c643e4f
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 586 deletions.
6 changes: 5 additions & 1 deletion custom_components/sat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ async def async_setup_entry(_hass: HomeAssistant, _entry: ConfigEntry):
_hass.data[DOMAIN][_entry.entry_id] = {CONFIG_STORE: SatConfigStore(_hass, _entry)}
await _hass.data[DOMAIN][_entry.entry_id][CONFIG_STORE].async_initialize()

# Retrieve the defaults and override it with the user options
options = OPTIONS_DEFAULTS.copy()
options.update(_entry.data)

# Get the module name from the config entry data and import it dynamically
module = getattr(sys.modules[__name__], _entry.data.get(CONF_MODE))
module = getattr(sys.modules[__name__], options.get(CONF_MODE))

# Call the async_setup_entry function of the module
await _hass.async_add_job(module.async_setup_entry, _hass, _entry)
Expand Down
6 changes: 4 additions & 2 deletions custom_components/sat/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.components import dhcp
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN, BinarySensorDeviceClass
from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
Expand Down Expand Up @@ -245,11 +245,13 @@ async def async_step_contact_sensors(self, _user_input=None) -> FlowResult:
return await self.update_options(_user_input)

defaults = await self.get_options()
device_class = [BinarySensorDeviceClass.WINDOW, BinarySensorDeviceClass.DOOR, BinarySensorDeviceClass.GARAGE_DOOR]

return self.async_show_form(
step_id="contact_sensors",
data_schema=vol.Schema({
vol.Optional(CONF_WINDOW_SENSOR, default=defaults[CONF_WINDOW_SENSOR]): selector.EntitySelector(
selector.EntitySelectorConfig(domain=BINARY_SENSOR_DOMAIN, device_class=BinarySensorDeviceClass.WINDOW)
selector.EntitySelectorConfig(domain=BINARY_SENSOR_DOMAIN, device_class=device_class)
),
})
)
Expand Down
2 changes: 1 addition & 1 deletion custom_components/sat/config_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async def async_initialize(self):
self._options.update(self._config_entry.options)

def get(self, key: str, default=None):
return self._data.get(key, default)
return self._data.get(key) or default

def update(self, key: str, value: float):
self._data[key] = value
Expand Down
Loading

0 comments on commit c643e4f

Please sign in to comment.