mirror of
https://github.com/home-assistant/core.git
synced 2025-04-27 18:57:57 +00:00
Make sure SmartThings light can deal with unknown states (#140190)
* Fix * add comment * Make light unknown * Make light unknown
This commit is contained in:
parent
38e6133202
commit
b5c7bdd98f
@ -147,14 +147,21 @@ class SmartThingsLight(SmartThingsEntity, LightEntity, RestoreEntity):
|
||||
"""Update entity attributes when the device status has changed."""
|
||||
# Brightness and transition
|
||||
if brightness_supported(self._attr_supported_color_modes):
|
||||
self._attr_brightness = int(
|
||||
convert_scale(
|
||||
self.get_attribute_value(Capability.SWITCH_LEVEL, Attribute.LEVEL),
|
||||
100,
|
||||
255,
|
||||
0,
|
||||
if (
|
||||
brightness := self.get_attribute_value(
|
||||
Capability.SWITCH_LEVEL, Attribute.LEVEL
|
||||
)
|
||||
) is None:
|
||||
self._attr_brightness = None
|
||||
else:
|
||||
self._attr_brightness = int(
|
||||
convert_scale(
|
||||
brightness,
|
||||
100,
|
||||
255,
|
||||
0,
|
||||
)
|
||||
)
|
||||
)
|
||||
# Color Temperature
|
||||
if ColorMode.COLOR_TEMP in self._attr_supported_color_modes:
|
||||
self._attr_color_temp_kelvin = self.get_attribute_value(
|
||||
@ -162,16 +169,21 @@ class SmartThingsLight(SmartThingsEntity, LightEntity, RestoreEntity):
|
||||
)
|
||||
# Color
|
||||
if ColorMode.HS in self._attr_supported_color_modes:
|
||||
self._attr_hs_color = (
|
||||
convert_scale(
|
||||
self.get_attribute_value(Capability.COLOR_CONTROL, Attribute.HUE),
|
||||
100,
|
||||
360,
|
||||
),
|
||||
self.get_attribute_value(
|
||||
Capability.COLOR_CONTROL, Attribute.SATURATION
|
||||
),
|
||||
)
|
||||
if (
|
||||
hue := self.get_attribute_value(Capability.COLOR_CONTROL, Attribute.HUE)
|
||||
) is None:
|
||||
self._attr_hs_color = None
|
||||
else:
|
||||
self._attr_hs_color = (
|
||||
convert_scale(
|
||||
hue,
|
||||
100,
|
||||
360,
|
||||
),
|
||||
self.get_attribute_value(
|
||||
Capability.COLOR_CONTROL, Attribute.SATURATION
|
||||
),
|
||||
)
|
||||
|
||||
async def async_set_color(self, hs_color):
|
||||
"""Set the color of the device."""
|
||||
@ -217,6 +229,10 @@ class SmartThingsLight(SmartThingsEntity, LightEntity, RestoreEntity):
|
||||
super()._update_handler(event)
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
def is_on(self) -> bool | None:
|
||||
"""Return true if light is on."""
|
||||
return self.get_attribute_value(Capability.SWITCH, Attribute.SWITCH) == "on"
|
||||
if (
|
||||
state := self.get_attribute_value(Capability.SWITCH, Attribute.SWITCH)
|
||||
) is None:
|
||||
return None
|
||||
return state == "on"
|
||||
|
@ -123,6 +123,7 @@ def mock_smartthings() -> Generator[AsyncMock]:
|
||||
"generic_ef00_v1",
|
||||
"bosch_radiator_thermostat_ii",
|
||||
"im_speaker_ai_0001",
|
||||
"abl_light_b_001",
|
||||
"tplink_p110",
|
||||
]
|
||||
)
|
||||
|
@ -0,0 +1,27 @@
|
||||
{
|
||||
"components": {
|
||||
"main": {
|
||||
"switchLevel": {
|
||||
"levelRange": {
|
||||
"value": null
|
||||
},
|
||||
"level": {
|
||||
"value": null
|
||||
}
|
||||
},
|
||||
"switch": {
|
||||
"switch": {
|
||||
"value": null
|
||||
}
|
||||
},
|
||||
"colorTemperature": {
|
||||
"colorTemperatureRange": {
|
||||
"value": null
|
||||
},
|
||||
"colorTemperature": {
|
||||
"value": null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
{
|
||||
"items": [
|
||||
{
|
||||
"deviceId": "7c16163e-c94e-482f-95f6-139ae0cd9d5e",
|
||||
"name": "ABL Wafer Down Light(BLE)",
|
||||
"label": "Kitchen Light 5",
|
||||
"manufacturerName": "Samsung Electronics",
|
||||
"presentationId": "ABL-LIGHT-B-001",
|
||||
"deviceManufacturerCode": "Samsung Electronics",
|
||||
"locationId": "6c314222-8baf-48a0-9442-5b1102a8757f",
|
||||
"ownerId": "f24ff388-700c-7d1e-91f2-1c37ae68ce2b",
|
||||
"components": [
|
||||
{
|
||||
"id": "main",
|
||||
"label": "main",
|
||||
"capabilities": [
|
||||
{
|
||||
"id": "switch",
|
||||
"version": 1
|
||||
},
|
||||
{
|
||||
"id": "colorTemperature",
|
||||
"version": 1
|
||||
},
|
||||
{
|
||||
"id": "switchLevel",
|
||||
"version": 1
|
||||
}
|
||||
],
|
||||
"categories": [
|
||||
{
|
||||
"name": "Light",
|
||||
"categoryType": "manufacturer"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"createTime": "2025-03-08T22:40:25.073Z",
|
||||
"profile": {
|
||||
"id": "65f5db53-9a78-4b19-8e40-d32187cd59ab"
|
||||
},
|
||||
"bleD2D": {
|
||||
"encryptionKey": "f593369dcea915f6352a4a42cd4b2ea6",
|
||||
"cipher": "AES_128-CBC-PKCS7Padding",
|
||||
"advertisingId": "b13d7192",
|
||||
"identifier": "88-57-1d-7c-cb-cf",
|
||||
"configurationUrl": "https://apis.samsungiotcloud.com/v1/miniature/profile/65f5db53-9a78-4b19-8e40-d32187cd59ab",
|
||||
"bleDeviceType": "BLE",
|
||||
"metadata": null
|
||||
},
|
||||
"type": "BLE_D2D",
|
||||
"restrictionTier": 0,
|
||||
"allowed": null,
|
||||
"executionContext": "CLOUD",
|
||||
"relationships": []
|
||||
}
|
||||
],
|
||||
"_links": {}
|
||||
}
|
@ -2,6 +2,39 @@
|
||||
# name: test_button_event[button]
|
||||
<Event smartthings.button[L]: component_id=main, device_id=c4bdd19f-85d1-4d58-8f9c-e75ac3cf113b, location_id=abc, value=pushed, name=button, data=None>
|
||||
# ---
|
||||
# name: test_devices[abl_light_b_001]
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'config_entries_subentries': <ANY>,
|
||||
'configuration_url': 'https://account.smartthings.com',
|
||||
'connections': set({
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': None,
|
||||
'hw_version': None,
|
||||
'id': <ANY>,
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'smartthings',
|
||||
'7c16163e-c94e-482f-95f6-139ae0cd9d5e',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'labels': set({
|
||||
}),
|
||||
'manufacturer': None,
|
||||
'model': None,
|
||||
'model_id': None,
|
||||
'name': 'Kitchen Light 5',
|
||||
'name_by_user': None,
|
||||
'primary_config_entry': <ANY>,
|
||||
'serial_number': None,
|
||||
'suggested_area': None,
|
||||
'sw_version': None,
|
||||
'via_device_id': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_devices[aeotec_home_energy_meter_gen5]
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
|
@ -1,4 +1,74 @@
|
||||
# serializer version: 1
|
||||
# name: test_all_entities[abl_light_b_001][light.kitchen_light_5-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
'max_color_temp_kelvin': 9000,
|
||||
'max_mireds': 500,
|
||||
'min_color_temp_kelvin': 2000,
|
||||
'min_mireds': 111,
|
||||
'supported_color_modes': list([
|
||||
<ColorMode.COLOR_TEMP: 'color_temp'>,
|
||||
]),
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'light',
|
||||
'entity_category': None,
|
||||
'entity_id': 'light.kitchen_light_5',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': None,
|
||||
'platform': 'smartthings',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': <LightEntityFeature: 32>,
|
||||
'translation_key': None,
|
||||
'unique_id': '7c16163e-c94e-482f-95f6-139ae0cd9d5e',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_all_entities[abl_light_b_001][light.kitchen_light_5-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'brightness': None,
|
||||
'color_mode': None,
|
||||
'color_temp': None,
|
||||
'color_temp_kelvin': None,
|
||||
'friendly_name': 'Kitchen Light 5',
|
||||
'hs_color': None,
|
||||
'max_color_temp_kelvin': 9000,
|
||||
'max_mireds': 500,
|
||||
'min_color_temp_kelvin': 2000,
|
||||
'min_mireds': 111,
|
||||
'rgb_color': None,
|
||||
'supported_color_modes': list([
|
||||
<ColorMode.COLOR_TEMP: 'color_temp'>,
|
||||
]),
|
||||
'supported_features': <LightEntityFeature: 32>,
|
||||
'xy_color': None,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'light.kitchen_light_5',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unknown',
|
||||
})
|
||||
# ---
|
||||
# name: test_all_entities[centralite][light.dimmer_debian-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
|
Loading…
x
Reference in New Issue
Block a user