From aeb2eb92fef1fed9d75c262c529900b71be744d0 Mon Sep 17 00:00:00 2001 From: KyGuy2002 Date: Fri, 14 Jun 2024 22:34:05 -0700 Subject: [PATCH 1/3] Fixed and added entity toggles --- custom_components/wyzeapi/light.py | 30 +++++++++++++++++++---------- custom_components/wyzeapi/sensor.py | 5 ++++- custom_components/wyzeapi/siren.py | 4 ++-- custom_components/wyzeapi/switch.py | 24 ++++++++++++++--------- 4 files changed, 41 insertions(+), 22 deletions(-) diff --git a/custom_components/wyzeapi/light.py b/custom_components/wyzeapi/light.py index e003dfcc..f9197e3f 100644 --- a/custom_components/wyzeapi/light.py +++ b/custom_components/wyzeapi/light.py @@ -62,9 +62,18 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, for camera in await camera_service.get_cameras(): - # Only model that I know of that has a floodlight - if camera.product_model == "WYZE_CAKP2JFUS" or camera.product_model == "HL_CFL2": - lights.append(WyzeCamerafloodlight(camera, camera_service)) + if ( + (camera.product_model == "WYZE_CAKP2JFUS" and camera.device_params['dongle_product_model'] == "HL_CFL") or # Cam v3 with floodlight accessory + (camera.product_model == "LD_CFP") or # Floodlight Pro + (camera.product_model == "HL_CFL2") # Floodlight v2 + ): + lights.append(WyzeCamerafloodlight(camera, camera_service, "floodlight")) + + elif ((camera.product_model == "WYZE_CAKP2JFUS" or camera.product_model == "HL_CAM4") and camera.device_params['dongle_product_model'] == "HL_CAM3SS"): # Cam v3 with lamp socket accessory + lights.append(WyzeCamerafloodlight(camera, camera_service, "lampsocket")) + + elif (camera.product_model == "AN_RSCW"): # Battery cam pro (integrated spotlight) + lights.append(WyzeCamerafloodlight(camera, camera_service, "spotlight")) async_add_entities(lights, True) @@ -363,17 +372,17 @@ class WyzeCamerafloodlight(LightEntity): _available: bool _just_updated = False - def __init__(self, camera: Camera, camera_service: CameraService) -> None: + def __init__(self, camera: Camera, camera_service: CameraService, light_type: str) -> None: self._device = camera self._service = camera_service - self._is_on = False + self._light_type = light_type @token_exception_handler async def async_turn_on(self, **kwargs) -> None: """Turn the floodlight on.""" await self._service.floodlight_on(self._device) - self._is_on = True + self._device.floodlight = True self._just_updated = True self.async_schedule_update_ha_state() @@ -382,7 +391,7 @@ async def async_turn_off(self, **kwargs): """Turn the floodlight off.""" await self._service.floodlight_off(self._device) - self._is_on = False + self._device.floodlight = False self._just_updated = True self.async_schedule_update_ha_state() @@ -398,11 +407,11 @@ def is_on(self): @property def name(self) -> str: - return f"{self._device.nickname} floodlight" + return f"{self._device.nickname} {"Lamp Socket" if self._light_type == "lampsocket" else ("Floodlight" if self._light_type == "floodlight" else "Spotlight")}" @property def unique_id(self): - return f"{self._device.mac}-floodlight" + return f"{self._device.mac}-{self._light_type}" @property def device_info(self): @@ -439,7 +448,8 @@ async def async_added_to_hass(self) -> None: @property def icon(self): """Return the icon to use in the frontend.""" - return "mdi:track-light" + + return "mdi:lightbulb" if self._light_type == "lampsocket" else ("mdi:track-light" if self._light_type == "floodlight" else "mdi:spotlight") @property def color_mode(self): diff --git a/custom_components/wyzeapi/sensor.py b/custom_components/wyzeapi/sensor.py index 25394f83..c831a53d 100644 --- a/custom_components/wyzeapi/sensor.py +++ b/custom_components/wyzeapi/sensor.py @@ -235,6 +235,7 @@ def should_poll(self) -> bool: @property def device_info(self): + """Return the device info.""" return { "identifiers": { (DOMAIN, self._camera.mac) @@ -245,7 +246,9 @@ def device_info(self): self._camera.mac, ) }, - "name": f"{self._camera.nickname}.battery" + "name": self._camera.nickname, + "model": self._camera.product_model, + "manufacturer": "WyzeLabs" } @property diff --git a/custom_components/wyzeapi/siren.py b/custom_components/wyzeapi/siren.py index a63f59a9..30597cac 100644 --- a/custom_components/wyzeapi/siren.py +++ b/custom_components/wyzeapi/siren.py @@ -40,8 +40,8 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, camera_service = await client.camera_service sirens = [] for camera in await camera_service.get_cameras(): - # The Campan and V2 cameras don't have a siren - if camera.product_model not in ["WYZECP1_JEF", "WYZEC1-JZ"]: + # The campan (v1 and 2), v2 camera, and video doorbell pro don't have sirens + if camera.product_model not in ["WYZECP1_JEF", "WYZEC1-JZ", "GW_BE1"]: sirens.append(WyzeCameraSiren(camera, camera_service)) async_add_entities(sirens, True) diff --git a/custom_components/wyzeapi/switch.py b/custom_components/wyzeapi/switch.py index bfe9d02a..2e728465 100644 --- a/custom_components/wyzeapi/switch.py +++ b/custom_components/wyzeapi/switch.py @@ -25,7 +25,8 @@ _LOGGER = logging.getLogger(__name__) ATTRIBUTION = "Data provided by Wyze" SCAN_INTERVAL = timedelta(seconds=30) -MOTION_SWITCH_UNSUPPORTED = ["GW_BE1", "LD_CFP"] # Doorbell Cam, Floodlight Pro +MOTION_SWITCH_UNSUPPORTED = ["GW_BE1"] # Video doorbell pro +POWER_SWITCH_UNSUPPORTED = ["GW_BE1"] # Video doorbell pro (device has no off function) # noinspection DuplicatedCode @token_exception_handler @@ -62,8 +63,15 @@ async def async_setup_entry( camera_switches = await camera_service.get_cameras() for switch in camera_switches: - switches.extend([WyzeSwitch(camera_service, switch)]) + + # Notification toggle switch switches.extend([WyzeCameraNotificationSwitch(camera_service, switch)]) + + # IoT Power switch + if switch.product_model not in POWER_SWITCH_UNSUPPORTED: + switches.extend([WyzeSwitch(camera_service, switch)]) + + # Motion toggle switch if switch.product_model not in MOTION_SWITCH_UNSUPPORTED: switches.extend([WyzeCameraMotionSwitch(camera_service, switch)]) @@ -307,18 +315,16 @@ class WyzeCameraNotificationSwitch(SwitchEntity): _available: bool - def __init__(self, service: CameraService, device: Device): + def __init__(self, service: CameraService, device: Camera): """Initialize a Wyze Notification Switch.""" self._service = service - self._device = Camera(device.raw_dict) + self._device = device @property def device_info(self): """Return the device info.""" return { - "identifiers": { - (DOMAIN, self._device.mac) - }, + "identifiers": {(DOMAIN, self._device.mac)}, "name": self._device.nickname, "manufacturer": "WyzeLabs", "model": self._device.product_model @@ -385,10 +391,10 @@ class WyzeCameraMotionSwitch(SwitchEntity): _available: bool - def __init__(self, service: CameraService, device: Device) -> None: + def __init__(self, service: CameraService, device: Camera) -> None: """Initialize a Wyze Notification Switch.""" self._service = service - self._device = Camera(device.raw_dict) + self._device = device @property def device_info(self): From 89efe3d92166b27f81d90284fdb7a403f5b17c54 Mon Sep 17 00:00:00 2001 From: Brian Rogers Date: Wed, 4 Sep 2024 11:54:17 -0400 Subject: [PATCH 2/3] Update custom_components/wyzeapi/siren.py Reword comment to show only V1 Campan not having a siren Signed-off-by: Brian Rogers --- custom_components/wyzeapi/siren.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/wyzeapi/siren.py b/custom_components/wyzeapi/siren.py index 30597cac..200daa83 100644 --- a/custom_components/wyzeapi/siren.py +++ b/custom_components/wyzeapi/siren.py @@ -40,7 +40,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, camera_service = await client.camera_service sirens = [] for camera in await camera_service.get_cameras(): - # The campan (v1 and 2), v2 camera, and video doorbell pro don't have sirens + # The campan v1, v2 camera, and video doorbell pro don't have sirens if camera.product_model not in ["WYZECP1_JEF", "WYZEC1-JZ", "GW_BE1"]: sirens.append(WyzeCameraSiren(camera, camera_service)) From e12ef51de28d1a7dee083c14ee3a458ca5dda0f5 Mon Sep 17 00:00:00 2001 From: IEatBeans <75859301+KyGuy2002@users.noreply.github.com> Date: Mon, 30 Sep 2024 20:15:48 -0700 Subject: [PATCH 3/3] Added OG cams to motion switch unsupported toggle --- custom_components/wyzeapi/switch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/wyzeapi/switch.py b/custom_components/wyzeapi/switch.py index 2e728465..e4cfa01a 100644 --- a/custom_components/wyzeapi/switch.py +++ b/custom_components/wyzeapi/switch.py @@ -25,7 +25,7 @@ _LOGGER = logging.getLogger(__name__) ATTRIBUTION = "Data provided by Wyze" SCAN_INTERVAL = timedelta(seconds=30) -MOTION_SWITCH_UNSUPPORTED = ["GW_BE1"] # Video doorbell pro +MOTION_SWITCH_UNSUPPORTED = ["GW_BE1", "GW_GC1", "GW_GC2"] # Video doorbell pro, OG, OG 3x Telephoto POWER_SWITCH_UNSUPPORTED = ["GW_BE1"] # Video doorbell pro (device has no off function) # noinspection DuplicatedCode