Skip to content

Commit

Permalink
Use device label for class discrimination
Browse files Browse the repository at this point in the history
references #210
  • Loading branch information
jason0x43 committed Apr 14, 2023
1 parent 2945e42 commit faa726e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions custom_components/hubitat/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,21 @@ def is_sensor(

def _get_contact_device_class(device: Device) -> str:
"""Guess the type of contact sensor from the device's label."""
name = device.name
label = device.label

for matcher in _CONTACT_MATCHERS:
if matcher[0].search(name):
if matcher[0].search(label):
return matcher[1]

return BinarySensorDeviceClass.DOOR


def _get_presence_device_class(device: Device) -> str:
"""Guess the type of presence sensor from the device's label."""
name = device.name
label = device.label

for matcher in _PRESENCE_MATCHERS:
if matcher[0].search(name):
if matcher[0].search(label):
return matcher[1]

return BinarySensorDeviceClass.CONNECTIVITY
2 changes: 1 addition & 1 deletion custom_components/hubitat/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ async def _async_step_override_type(
default_value = []

possible_overrides = {
id: devices[id].name for id in devices if matcher(devices[id])
id: devices[id].label for id in devices if matcher(devices[id])
}

if existing_overrides:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hubitat/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def is_light(device: Device, overrides: Optional[Dict[str, str]] = None) -> bool
if is_definitely_light(device):
return True
if DeviceCapability.SWITCH in device.capabilities and MATCH_LIGHT.search(
device.name
device.label
):
return True
if DeviceCapability.LIGHT in device.capabilities:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hubitat/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def is_on(self) -> bool:
@property
def device_class(self) -> Optional[str]:
"""Return the class of this device, from component DEVICE_CLASSES."""
if _NAME_TEST.search(self._device.name):
if _NAME_TEST.search(self._device.label):
return SwitchDeviceClass.SWITCH
return SwitchDeviceClass.OUTLET

Expand Down

0 comments on commit faa726e

Please sign in to comment.