Skip to content

Commit

Permalink
Prevent unsupported devices from being configured
Browse files Browse the repository at this point in the history
  • Loading branch information
schmittx committed Dec 17, 2024
1 parent c9e82dd commit 78f09e6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
4 changes: 3 additions & 1 deletion custom_components/leviton_decora_smart_wifi/api/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,16 @@
},
]

SUPPORTED_DEVICES_MODEL = [device[DEVICE_MODEL] for device in SUPPORTED_DEVICES]

SUPPORTED_DEVICES_CONTROLLER = [device[DEVICE_MODEL] for device in SUPPORTED_DEVICES if DEVICE_TYPE_CONTROLLER in device[DEVICE_TYPE]]
SUPPORTED_DEVICES_FAN = [device[DEVICE_MODEL] for device in SUPPORTED_DEVICES if DEVICE_TYPE_FAN in device[DEVICE_TYPE]]
SUPPORTED_DEVICES_GFCI = [device[DEVICE_MODEL] for device in SUPPORTED_DEVICES if DEVICE_TYPE_GFCI in device[DEVICE_TYPE]]
SUPPORTED_DEVICES_LIGHT = [device[DEVICE_MODEL] for device in SUPPORTED_DEVICES if DEVICE_TYPE_LIGHT in device[DEVICE_TYPE]]
SUPPORTED_DEVICES_OUTLET = [device[DEVICE_MODEL] for device in SUPPORTED_DEVICES if DEVICE_TYPE_OUTLET in device[DEVICE_TYPE]]
SUPPORTED_DEVICES_SWITCH = [device[DEVICE_MODEL] for device in SUPPORTED_DEVICES if DEVICE_TYPE_SWITCH in device[DEVICE_TYPE]]

SECOND_GENERATION_DEVICES = [device[DEVICE_MODEL] for device in SUPPORTED_DEVICES if device[DEVICE_GENERATION] == DEVICE_GENERATION_2]
SUPPORTED_DEVICES_SECOND_GENERATION = [device[DEVICE_MODEL] for device in SUPPORTED_DEVICES if device[DEVICE_GENERATION] == DEVICE_GENERATION_2]

STATUS_AWAY = "away"
STATUS_HOME = "home"
Expand Down
9 changes: 7 additions & 2 deletions custom_components/leviton_decora_smart_wifi/api/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
MOTION_TIMEOUT_UNKNOWN,
POWER_OFF,
POWER_ON,
SECOND_GENERATION_DEVICES,
STATUS_LED_DISABLED,
STATUS_LED_ENABLED,
STATUS_LED_MODE_MAP,
Expand All @@ -45,7 +44,9 @@
SUPPORTED_DEVICES_FAN,
SUPPORTED_DEVICES_GFCI,
SUPPORTED_DEVICES_LIGHT,
SUPPORTED_DEVICES_MODEL,
SUPPORTED_DEVICES_OUTLET,
SUPPORTED_DEVICES_SECOND_GENERATION,
SUPPORTED_DEVICES_SWITCH,
TIME_PERIOD_UNKNOWN,
)
Expand Down Expand Up @@ -841,6 +842,10 @@ def buttons(self) -> list[Button]:
return [button for button in buttons if button.number != 4]
return buttons

@property
def is_supported(self) -> bool:
return bool(self.model in SUPPORTED_DEVICES_MODEL)

@property
def is_controller(self) -> bool:
return bool(self.model in SUPPORTED_DEVICES_CONTROLLER)
Expand Down Expand Up @@ -899,7 +904,7 @@ def is_switch(self) -> bool:

@property
def is_second_generation(self) -> bool:
return bool(self.model in SECOND_GENERATION_DEVICES)
return bool(self.model in SUPPORTED_DEVICES_SECOND_GENERATION)

@property
def has_led_bar(self) -> bool:
Expand Down
4 changes: 2 additions & 2 deletions custom_components/leviton_decora_smart_wifi/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ async def async_step_devices(self, user_input=None):

for residence in self.response:
if residence.id == self.user_input[CONF_RESIDENCES][self.index]:
device_names = sorted(device.name for device in residence.devices)
device_names = sorted(device.name for device in residence.devices if device.is_supported)

if not device_names:
self.index += 1
Expand Down Expand Up @@ -252,7 +252,7 @@ async def async_step_devices(self, user_input=None):
for residence in self.coordinator.data:
if residence.id == self.user_input[CONF_RESIDENCES][self.index]:
conf_devices = sorted([device.name for device in residence.devices if device.id in self.options.get(CONF_DEVICES, self.data[CONF_DEVICES])])
device_names = sorted(device.name for device in residence.devices)
device_names = sorted(device.name for device in residence.devices if device.is_supported)

return self.async_show_form(
step_id="devices",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/leviton_decora_smart_wifi/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"loggers": [],
"quality_scale": "gold",
"requirements": ["pypng==0.20220715.0", "PyQRCode==1.2.1"],
"version": "1.6.0"
"version": "1.6.1"
}

0 comments on commit 78f09e6

Please sign in to comment.