SmartThings Component Enhancements/Fixes (#21085)
* Improve component setup error logging/notification * Prevent capabilities from being represented my multiple platforms * Improved logging of received updates * Updates based on review feedback
This commit is contained in:
1 parent
7d0f847f83
commit
93f84a5cd1
20 files changed
+196
-151
No files matched your search
@@ -1,4 +1,6 @@
|
||||
"""Support for switches through the SmartThings cloud API."""
|
||||
from typing import Optional, Sequence
|
||||
|
||||
from homeassistant.components.switch import SwitchDevice
|
||||
|
||||
from . import SmartThingsEntity
|
||||
@@ -18,28 +20,17 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
broker = hass.data[DOMAIN][DATA_BROKERS][config_entry.entry_id]
|
||||
async_add_entities(
|
||||
[SmartThingsSwitch(device) for device in broker.devices.values()
|
||||
if is_switch(device)])
|
||||
if broker.any_assigned(device.device_id, 'switch')])
|
||||
|
||||
|
||||
def is_switch(device):
|
||||
"""Determine if the device should be represented as a switch."""
|
||||
def get_capabilities(capabilities: Sequence[str]) -> Optional[Sequence[str]]:
|
||||
"""Return all capabilities supported if minimum required are present."""
|
||||
from pysmartthings import Capability
|
||||
|
||||
# Must be able to be turned on/off.
|
||||
if Capability.switch not in device.capabilities:
|
||||
return False
|
||||
# Must not have a capability represented by other types.
|
||||
non_switch_capabilities = [
|
||||
Capability.color_control,
|
||||
Capability.color_temperature,
|
||||
Capability.fan_speed,
|
||||
Capability.switch_level
|
||||
]
|
||||
if any(capability in device.capabilities
|
||||
for capability in non_switch_capabilities):
|
||||
return False
|
||||
|
||||
return True
|
||||
if Capability.switch in capabilities:
|
||||
return [Capability.switch]
|
||||
return None
|
||||
|
||||
|
||||
class SmartThingsSwitch(SmartThingsEntity, SwitchDevice):
|
||||
|
||||
Reference in new issue
Block a user