Skip to main content

Usage

from hikconnect.api import HikConnect

async with HikConnect() as api:

    await api.login("foo", "bar")

    devices = [device async for device in api.get_devices()]
    print(devices)
    # [{
    #   'id': 'DS-XXXXXX-YYYYYYYYYYYYYYYYYYYYYYYYY',
    #   'name': 'DS-XXXXXX-Y(ZZZZZZZZZ)',
    #   'serial': 'ZZZZZZZZZ',
    #   'type': 'DS-XXXXXX-Y',
    #   'version': 'V1.2.3 build 123456',
    #   'locks': {1: 2, 2: 0, 3: 1}
    # }]
    # locks data means (guessing): <channel number>: <number of locks connected>

    my_device_serial = devices[0]["serial"]

    cameras = [camera async for camera in api.get_cameras(my_device_serial)]
    print(cameras)
    # [
    #   {'id': '4203fd7c5f89ce96f8ff0adfdbe8b731', 'name': 'foo', 'channel_number': 1, 'signal_status': 1, 'is_shown': 0},
    #   {'id': 'cd72bc923956952194468738123b7a5e', 'name': 'bar', 'channel_number': 2, 'signal_status': 1, 'is_shown': 1},
    #   {'id': 'd2a2057d853438d9a5b4954baec136e3', 'name': 'baz', 'channel_number': 3, 'signal_status': 0, 'is_shown': 0}
    # ]

    call_status = await api.get_call_status(my_device_serial)
    print(call_status)
    # {
    #   'status': 'idle',
    #   'info': {
    #     'building_number': 0,
    #     'floor_number': 0,
    #     'zone_number': 0,
    #     'unit_number': 0,
    #     'device_number': 0,
    #     'device_type': 0,
    #     'lock_number': 0
    #   }
    # }
    # can be "idle" / "ringing" / "call in progress" - see hikconnect/api.py:45
    
    # Unlock device
    await api.unlock(my_device_serial, 1)
    
    # Cancel call for device
    await api.cancel_call(my_device_serial)

    # call this periodically at least once per 30 mins!
    if api.is_refresh_login_needed():
        await api.refresh_login()

    # ---- Area (group) management ----------------------------------------

    # List all areas on a device
    areas = [area async for area in api.get_areas(my_device_serial)]
    print(areas)
    # [
    #   {
    #     'group_id': 110548,
    #     'device_serial': 'ZZZZZZZZZ',
    #     'group_name': 'Entrance',
    #     'group_type': 2,
    #     'mode': 1,           # 0=disarmed, 1=armed, 2=armed-silent
    #     'create_time': 1737221666000,
    #     'modify_time': 1737221666000,
    #   },
    #   ...
    # ]

    my_group_id = areas[0]["group_id"]

    # Get cameras (resources) assigned to an area
    members = await api.get_area(my_device_serial, my_group_id)
    print(members)
    # [
    #   {'group_id': 110548, 'device_serial': 'ZZZZZZZZZ', 'member_id': 'abc123...'},
    #   ...
    # ]
    # member_id corresponds to camera id returned by get_cameras()

    # Create a new area with specific cameras
    cameras = [camera async for camera in api.get_cameras(my_device_serial)]
    camera_ids = [c["id"] for c in cameras[:2]]  # first two cameras
    result = await api.create_area(my_device_serial, "Front Gate", camera_ids)
    new_group_id = result["group_id"]

    # Update an existing area (rename and/or change cameras)
    await api.update_area(my_device_serial, my_group_id, "New Name", camera_ids)

    # Arm / disarm an area
    await api.arm_area(my_device_serial, my_group_id)           # mode=1
    await api.arm_area_silent(my_device_serial, my_group_id)    # mode=2 (no beep)
    await api.disarm_area(my_device_serial, my_group_id)        # mode=0

    # Delete an area
    await api.delete_area(my_device_serial, my_group_id)

If you are new to async Python, you simply need to wrap your code in a construction like this:

import asyncio

async def main():
    # put the original code containing `async` keywords here

asyncio.run(main())

More info in the async docs.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hikconnect-2.1.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hikconnect-2.1.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file hikconnect-2.1.0.tar.gz.

File metadata

  • Download URL: hikconnect-2.1.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.6 Darwin/25.5.0

File hashes

Hashes for hikconnect-2.1.0.tar.gz
Algorithm Hash digest
SHA256 af6c5ef7b62c75337b93fb80087127725bab2d7321dbd7bc5e1205961d43afb8
MD5 0b7225fa17a1c9f0fe1bac15c5c1cf3e
BLAKE2b-256 a1ad62797c4d70fde467916b90504dbdc21ed13eae0b8c5dd32a9e7d0c1020f7

See more details on using hashes here.

File details

Details for the file hikconnect-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: hikconnect-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.6 Darwin/25.5.0

File hashes

Hashes for hikconnect-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5ed98ed6075c7e92bea2d15b3fef0cd8a9f185c55d52681cc6e169c69bba17e0
MD5 0e0cd2b7cca9c241062f10498aa7cd46
BLAKE2b-256 5c41192bd25950f2bfd4c7f03efdf210feb285752267bf2925e507d6b7f8c1b5

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 files

2.0.1

2 files

2.0.0

2 files

1.3.0

2 files

1.2.1

2 files

1.2.0

2 files

1.1.0

2 files

1.0.0

2 files

0.7.3

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page