Skip to content

Commit

Permalink
Merge branch 'master' into Update-error-handling
Browse files Browse the repository at this point in the history
Signed-off-by: Katie Mulliken <[email protected]>
  • Loading branch information
SecKatie authored Oct 8, 2024
2 parents b487c2b + 524cb19 commit c4f331a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 20 deletions.
26 changes: 18 additions & 8 deletions custom_components/wyzeapi/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,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)

Expand Down Expand Up @@ -367,10 +376,10 @@ 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:
Expand Down Expand Up @@ -412,11 +421,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):
Expand Down Expand Up @@ -453,7 +462,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):
Expand Down
5 changes: 4 additions & 1 deletion custom_components/wyzeapi/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ def should_poll(self) -> bool:

@property
def device_info(self):
"""Return the device info."""
return {
"identifiers": {
(DOMAIN, self._camera.mac)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions custom_components/wyzeapi/siren.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,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, 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)
Expand Down
24 changes: 15 additions & 9 deletions custom_components/wyzeapi/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,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", "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
@token_exception_handler
Expand Down Expand Up @@ -64,8 +65,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)])

Expand Down Expand Up @@ -320,18 +328,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
Expand Down Expand Up @@ -409,10 +415,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):
Expand Down

0 comments on commit c4f331a

Please sign in to comment.