diff --git a/custom_components/wyzeapi/light.py b/custom_components/wyzeapi/light.py index df5d0491..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": - 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 7674fef3..1be26fb9 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):