Use category to define SmartThings binary sensor device class (#141075)

* Use category to define SmartThings binary sensor device class

* Fix
This commit is contained in:
Joost Lekkerkerker 2025-03-22 18:41:15 +01:00 committed by GitHub
parent 92c619cdd6
commit 931ce8951e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 70 additions and 57 deletions

View File

@ -33,6 +33,7 @@ class SmartThingsBinarySensorEntityDescription(BinarySensorEntityDescription):
"""Describe a SmartThings binary sensor entity."""
is_on_key: str
category_device_class: dict[Category | str, BinarySensorDeviceClass] | None = None
category: set[Category] | None = None
@ -52,6 +53,11 @@ CAPABILITY_TO_SENSORS: dict[
key=Attribute.CONTACT,
device_class=BinarySensorDeviceClass.DOOR,
is_on_key="open",
category_device_class={
Category.GARAGE_DOOR: BinarySensorDeviceClass.GARAGE_DOOR,
Category.DOOR: BinarySensorDeviceClass.DOOR,
Category.WINDOW: BinarySensorDeviceClass.WINDOW,
},
)
},
Capability.FILTER_STATUS: {
@ -186,6 +192,13 @@ class SmartThingsBinarySensor(SmartThingsEntity, BinarySensorEntity):
self.capability = capability
self.entity_description = entity_description
self._attr_unique_id = f"{device.device.device_id}.{attribute}"
if (
entity_description.category_device_class
and (category := get_main_component_category(device))
in entity_description.category_device_class
):
self._attr_device_class = entity_description.category_device_class[category]
self._attr_name = None
@property
def is_on(self) -> bool:

View File

@ -42,7 +42,7 @@
"categoryType": "manufacturer"
},
{
"name": "ContactSensor",
"name": "GarageDoor",
"categoryType": "user"
}
]

View File

@ -95,7 +95,7 @@
'state': 'off',
})
# ---
# name: test_all_entities[contact_sensor][binary_sensor.front_door_open_closed_sensor_door-entry]
# name: test_all_entities[contact_sensor][binary_sensor.front_door_open_closed_sensor-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
@ -108,7 +108,7 @@
'disabled_by': None,
'domain': 'binary_sensor',
'entity_category': None,
'entity_id': 'binary_sensor.front_door_open_closed_sensor_door',
'entity_id': 'binary_sensor.front_door_open_closed_sensor',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
@ -118,9 +118,9 @@
'name': None,
'options': dict({
}),
'original_device_class': <BinarySensorDeviceClass.DOOR: 'door'>,
'original_device_class': <BinarySensorDeviceClass.GARAGE_DOOR: 'garage_door'>,
'original_icon': None,
'original_name': 'Door',
'original_name': None,
'platform': 'smartthings',
'previous_unique_id': None,
'supported_features': 0,
@ -129,14 +129,14 @@
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[contact_sensor][binary_sensor.front_door_open_closed_sensor_door-state]
# name: test_all_entities[contact_sensor][binary_sensor.front_door_open_closed_sensor-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'door',
'friendly_name': '.Front Door Open/Closed Sensor Door',
'device_class': 'garage_door',
'friendly_name': '.Front Door Open/Closed Sensor',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.front_door_open_closed_sensor_door',
'entity_id': 'binary_sensor.front_door_open_closed_sensor',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
@ -1279,6 +1279,54 @@
'state': 'on',
})
# ---
# name: test_all_entities[multipurpose_sensor][binary_sensor.deck_door-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'binary_sensor',
'entity_category': None,
'entity_id': 'binary_sensor.deck_door',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <BinarySensorDeviceClass.DOOR: 'door'>,
'original_icon': None,
'original_name': None,
'platform': 'smartthings',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': None,
'unique_id': '7d246592-93db-4d72-a10d-5a51793ece8c.contact',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[multipurpose_sensor][binary_sensor.deck_door-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'door',
'friendly_name': 'Deck Door',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.deck_door',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_all_entities[multipurpose_sensor][binary_sensor.deck_door_acceleration-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
@ -1327,54 +1375,6 @@
'state': 'off',
})
# ---
# name: test_all_entities[multipurpose_sensor][binary_sensor.deck_door_door-entry]
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'config_subentry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'binary_sensor',
'entity_category': None,
'entity_id': 'binary_sensor.deck_door_door',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'labels': set({
}),
'name': None,
'options': dict({
}),
'original_device_class': <BinarySensorDeviceClass.DOOR: 'door'>,
'original_icon': None,
'original_name': 'Door',
'platform': 'smartthings',
'previous_unique_id': None,
'supported_features': 0,
'translation_key': None,
'unique_id': '7d246592-93db-4d72-a10d-5a51793ece8c.contact',
'unit_of_measurement': None,
})
# ---
# name: test_all_entities[multipurpose_sensor][binary_sensor.deck_door_door-state]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'door',
'friendly_name': 'Deck Door Door',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.deck_door_door',
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'off',
})
# ---
# name: test_all_entities[virtual_valve][binary_sensor.volvo_valve-entry]
EntityRegistryEntrySnapshot({
'aliases': set({