Skip to content

Commit

Permalink
Ensure that tags resolve to the parent class and not one of the child…
Browse files Browse the repository at this point in the history
…ren.
  • Loading branch information
jaraco committed Jul 11, 2024
1 parent b5973e0 commit b36b107
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion jaraco/abode/devices/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,13 @@ def by_type(cls):

@classmethod
def resolve_class(cls, type_tag):
"""
>>> Device.resolve_class('device_type.povs')
<class 'jaraco.abode.devices.binary_sensor.Motion'>
"""
lookup = {
f'device_type.{tag}': sub_cls
for sub_cls in iter_subclasses(cls)
for sub_cls in reversed(tuple(iter_subclasses(cls)))
for tag in sub_cls.tags
}
return lookup.get(type_tag.lower(), Unknown)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import itertools

import jaraco.abode.devices.status as STATUS
from jaraco.abode.devices import base
from jaraco.abode.helpers import urls

from .mock import login as LOGIN
Expand Down Expand Up @@ -149,6 +150,11 @@ def test_binary_sensor_properties(self, m):
assert device.no_response, device.type + " no_response failed"


def test_binary_sensor_classes():
device = base.Device.new(OCCUPANCY.device(), None)
assert device.generic_type == 'motion'


def is_alarm(device):
return device.type_tag == 'device_type.alarm'

Expand Down

0 comments on commit b36b107

Please sign in to comment.