async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities): _LOGGER.debug("""Creating new WyzeApi light component""") client = hass.data[DOMAIN][config_entry.entry_id] def get_devices() -> List[Device]: try: devices = client.get_devices() except AccessTokenError as e: _LOGGER.warning(e) client.reauthenticate() devices = client.get_devices() return devices devices = await hass.async_add_executor_job(get_devices) lights = [] color_lights = [] for device in devices: try: if DeviceTypes(device.product_type) == DeviceTypes.LIGHT: lights.append(WyzeLight(client, device)) if DeviceTypes(device.product_type) == DeviceTypes.MESH_LIGHT: color_lights.append(WyzeColorLight(client, device)) except ValueError as e: _LOGGER.warning( "{}: Please report this error to https://github.com/JoshuaMulliken/ha-wyzeapi" .format(e)) async_add_entities(lights, True) async_add_entities(color_lights, True)
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities): _LOGGER.debug("""Creating new WyzeApi light component""") client = hass.data[DOMAIN][config_entry.entry_id] def get_devices() -> List[Device]: try: devices = client.get_devices() except AccessTokenError as e: _LOGGER.warning(e) client.reauthenticate() devices = client.get_devices() return devices devices = await hass.async_add_executor_job(get_devices) plugs = [] for device in devices: try: device_type = DeviceTypes(device.product_type) if device_type == DeviceTypes.PLUG or \ device_type == DeviceTypes.OUTDOOR_PLUG or \ device_type == DeviceTypes.CAMERA: plugs.append(WyzeSwitch(client, device)) except ValueError as e: _LOGGER.warning("{}: Please report this error to https://github.com/JoshuaMulliken/ha-wyzeapi".format(e)) async_add_entities(plugs, True)
def __init__(self, client: Client, device: Device): """Initialize a Wyze Bulb.""" self._device = device if DeviceTypes(self._device.product_type) not in [DeviceTypes.LIGHT]: raise AttributeError("Device type not supported") self._client = client
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the sensor platform.""" _ = config # We only want this platform to be set up via discovery. if discovery_info is None: return _LOGGER.debug("""Creating new WyzeApi light component""") wyzeapi_client: Client = hass.data[DOMAIN]['wyzeapi_client'] devices = hass.data[DOMAIN]['devices'] plugs = [] for device in devices: if DeviceTypes(device.product_type) == DeviceTypes.PLUG: plugs.append(WyzeSwitch(wyzeapi_client, device)) if DeviceTypes(device.product_type) == DeviceTypes.OUTDOOR_PLUG: plugs.append(WyzeSwitch(wyzeapi_client, device)) add_entities(plugs, True)
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the sensor platform.""" _ = config # We only want this platform to be set up via discovery. if discovery_info is None: return _LOGGER.debug("""Creating new WyzeApi light component""") wyzeapi_client: Client = hass.data[DOMAIN]['wyzeapi_client'] devices = hass.data[DOMAIN]['devices'] lights = [] color_lights = [] for device in devices: if DeviceTypes(device.product_type) == DeviceTypes.LIGHT: lights.append(WyzeLight(wyzeapi_client, device)) if DeviceTypes(device.product_type) == DeviceTypes.MESH_LIGHT: color_lights.append(WyzeColorLight(wyzeapi_client, device)) add_entities(lights, True) add_entities(color_lights, True)