Skip to content

Commit

Permalink
Merge pull request #106 from blockarchitech/garage-door
Browse files Browse the repository at this point in the history
feat: garage door controller.
  • Loading branch information
SecKatie authored Feb 19, 2025
2 parents 3aee464 + 9b88620 commit 4996abc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
4 changes: 1 addition & 3 deletions src/wyzeapy/services/base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BaseService:
_devices: Optional[List[Device]] = None
_last_updated_time: time = 0 # preload a value of 0 so that comparison will succeed on the first run
_min_update_time = 1200 # lets let the device_params update every 20 minutes for now. This could probably reduced signicficantly.
_update_lock: asyncio.Lock = asyncio.Lock()
_update_lock: asyncio.Lock = asyncio.Lock() # fmt: skip
_update_manager: UpdateManager = UpdateManager()
_update_loop = None
_updater: DeviceUpdater = None
Expand Down Expand Up @@ -120,7 +120,6 @@ async def get_object_list(self) -> List[Device]:
json=payload)

check_for_errors_standard(self, response_json)

# Cache the devices so that update calls can pull more recent device_params
BaseService._devices = [Device(device) for device in response_json['data']['device_list']]

Expand Down Expand Up @@ -166,7 +165,6 @@ async def _get_property_list(self, device: Device) -> List[Tuple[PropertyIDs, An

check_for_errors_standard(self, response_json)
properties = response_json['data']['property_list']

property_list = []
for prop in properties:
try:
Expand Down
18 changes: 14 additions & 4 deletions src/wyzeapy/services/camera_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(self, dictionary: Dict[Any, Any]):
self.on: bool = True
self.siren: bool = False
self.floodlight: bool = False
self.garage: bool = False


class CameraService(BaseService):
Expand Down Expand Up @@ -76,8 +77,10 @@ async def update(self, camera: Camera):
camera.on = value == "1"
if property is PropertyIDs.CAMERA_SIREN:
camera.siren = value == "1"
if property is PropertyIDs.FLOOD_LIGHT:
if property is PropertyIDs.ACCESSORY:
camera.floodlight = value == "1"
if camera.device_params["dongle_product_model"] == "HL_CGDC":
camera.garage = value == "1" # 1 = open, 2 = closed by automation or smart platform (Alexa, Google Home, Rules), 0 = closed by app
if property is PropertyIDs.NOTIFICATION:
camera.notify = value == "1"
if property is PropertyIDs.MOTION_DETECTION:
Expand Down Expand Up @@ -139,14 +142,21 @@ async def siren_off(self, camera: Camera):
async def floodlight_on(self, camera: Camera):
if (camera.product_model == "AN_RSCW"): await self._run_action_devicemgmt(camera, "spotlight", "1") # Battery cam pro integrated spotlight is controllable
elif (camera.product_model in DEVICEMGMT_API_MODELS): await self._run_action_devicemgmt(camera, "floodlight", "1") # Some camera models use a diffrent api
else: await self._set_property(camera, PropertyIDs.FLOOD_LIGHT.value, "1")
else: await self._set_property(camera, PropertyIDs.ACCESSORY.value, "1")

# Also controls lamp socket and BCP spotlight
async def floodlight_off(self, camera: Camera):
if (camera.product_model == "AN_RSCW"): await self._run_action_devicemgmt(camera, "spotlight", "0") # Battery cam pro integrated spotlight is controllable
elif (camera.product_model in DEVICEMGMT_API_MODELS): await self._run_action_devicemgmt(camera, "floodlight", "0") # Some camera models use a diffrent api
else: await self._set_property(camera, PropertyIDs.FLOOD_LIGHT.value, "2")

else: await self._set_property(camera, PropertyIDs.ACCESSORY.value, "2")

# Garage door trigger uses run action on all models
async def garage_door_open(self, camera: Camera):
await self._run_action(camera, "garage_door_trigger")

async def garage_door_close(self, camera: Camera):
await self._run_action(camera, "garage_door_trigger")

async def turn_on_notifications(self, camera: Camera):
if (camera.product_model in DEVICEMGMT_API_MODELS): await self._set_toggle(camera, DeviceMgmtToggleProps.NOTIFICATION_TOGGLE.value, "1")
else: await self._set_property(camera, PropertyIDs.NOTIFICATION.value, "1")
Expand Down
6 changes: 3 additions & 3 deletions src/wyzeapy/tests/test_camera_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def test_update_legacy_camera(self):
(PropertyIDs.AVAILABLE, "1"),
(PropertyIDs.ON, "1"),
(PropertyIDs.CAMERA_SIREN, "0"),
(PropertyIDs.FLOOD_LIGHT, "0"),
(PropertyIDs.ACCESSORY, "0"),
(PropertyIDs.NOTIFICATION, "1"),
(PropertyIDs.MOTION_DETECTION, "1")
]
Expand Down Expand Up @@ -125,14 +125,14 @@ async def test_floodlight_control_legacy_camera(self):
await self.camera_service.floodlight_on(self.test_camera)
self.camera_service._set_property.assert_awaited_with(
self.test_camera,
PropertyIDs.FLOOD_LIGHT.value,
PropertyIDs.ACCESSORY.value,
"1"
)

await self.camera_service.floodlight_off(self.test_camera)
self.camera_service._set_property.assert_awaited_with(
self.test_camera,
PropertyIDs.FLOOD_LIGHT.value,
PropertyIDs.ACCESSORY.value,
"2"
)

Expand Down
4 changes: 3 additions & 1 deletion src/wyzeapy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class DeviceTypes(Enum):
CHIME_SENSOR = "ChimeSensor"
CONTACT_SENSOR = "ContactSensor"
MOTION_SENSOR = "MotionSensor"
LEAK_SENSOR = "LeakSensor"
WRIST = "Wrist"
BASE_STATION = "BaseStation"
SCALE = "WyzeScale"
Expand All @@ -43,6 +44,7 @@ class DeviceTypes(Enum):
KEYPAD = "Keypad"
LIGHTSTRIP = "LightStrip"


class Device:
product_type: str
product_model: str
Expand Down Expand Up @@ -102,7 +104,7 @@ class PropertyIDs(Enum):
CONTACT_STATE = "P1301"
MOTION_STATE = "P1302"
CAMERA_SIREN = "P1049"
FLOOD_LIGHT = "P1056" # Also lamp socket on v3/v4 with lamp socket accessory
ACCESSORY = "P1056" # Is state for camera accessories, like garage doors, light sockets, and floodlights.
SUN_MATCH = "P1528"
MOTION_DETECTION = "P1047" # Current Motion Detection State of the Camera
MOTION_DETECTION_TOGGLE = "P1001" # This toggles Camera Motion Detection On/Off
Expand Down

0 comments on commit 4996abc

Please sign in to comment.