Skip to content

Commit

Permalink
Version 1.7. Details in /releases/release_1.7.md
Browse files Browse the repository at this point in the history
  • Loading branch information
tropicoo committed Oct 18, 2022
1 parent da14bc6 commit 6242f3a
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 9 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Hikvision Telegram Camera Bot
Telegram Bot which sends snapshots from your Hikvision cameras.

Version: 1.6. [Release details](releases/release_1.6.md).
Version: 1.7. [Release details](releases/release_1.7.md).

## Features
1. Send full/resized pictures on request.
Expand Down Expand Up @@ -50,8 +50,10 @@ Configuration files are stored in JSON format and can be found in the `configs`
digit suffix**: `cam_1`, `cam_2`, `cam_<digit>` with any description.

5. Write authentication credentials in `user` and `password` keys for every camera
6. Same for `host`, which should include protocol e.g., `http://192.168.1.1`
7. In the `alert` section you can enable sending pictures on alert (Motion,
6. Choose authentication type from `basic`, `digest` or `digest_cached`. Default is `digest_cached`.
Check your camera security settings before choosing/changing one.
7. Write `host`, which should include protocol e.g., `http://192.168.1.1`
8. In the `alert` section you can enable sending pictures on alert (Motion,
Line Crossing and Intrusion (Field) Detection). Configure the `delay` setting
in seconds between pushing alert pictures. To send resized picture change
`fullpic` to `false`
Expand Down Expand Up @@ -89,7 +91,8 @@ Configuration files are stored in JSON format and can be found in the `configs`
"port": 80,
"auth": {
"user": "dummy-user",
"password": "dummy-password"
"password": "dummy-password",
"type": "digest_cached"
},
"stream_timeout": 10
},
Expand Down
6 changes: 4 additions & 2 deletions configs/config-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"port": 80,
"auth": {
"user": "dummy-user",
"password": "dummy-password"
"password": "dummy-password",
"type": "digest_cached"
},
"stream_timeout": 10
},
Expand Down Expand Up @@ -144,7 +145,8 @@
"port": 80,
"auth": {
"user": "dummy-user",
"password": "dummy-password"
"password": "dummy-password",
"type": "digest_cached"
},
"stream_timeout": 10
},
Expand Down
10 changes: 8 additions & 2 deletions hikcamerabot/clients/hikvision/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,27 @@
from tenacity import retry, wait_fixed

from hikcamerabot.clients.hikvision.auth import DigestAuthCached
from hikcamerabot.clients.hikvision.enums import EndpointAddr
from hikcamerabot.clients.hikvision.enums import AuthType, EndpointAddr
from hikcamerabot.constants import CONN_TIMEOUT
from hikcamerabot.exceptions import APIBadResponseCodeError, APIRequestError


class HikvisionAPIClient:
"""Hikvision API Class."""

AUTH_CLS = {
AuthType.BASIC: httpx.BasicAuth,
AuthType.DIGEST: httpx.DigestAuth,
AuthType.DIGEST_CACHED: DigestAuthCached,
}

def __init__(self, conf: Dict) -> None:
self._log = logging.getLogger(self.__class__.__name__)
self._conf = conf
self.host: str = self._conf.host
self.port: int = self._conf.port
self.session = httpx.AsyncClient(
auth=DigestAuthCached(
auth=self.AUTH_CLS[AuthType(self._conf.auth.type)](
username=self._conf.auth.user,
password=self._conf.auth.password,
),
Expand Down
10 changes: 10 additions & 0 deletions hikcamerabot/clients/hikvision/enums.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import enum


class AuthType(enum.Enum):
BASIC = 'basic'
DIGEST = 'digest'
DIGEST_CACHED = 'digest_cached'

@classmethod
def choices(cls) -> frozenset[str]:
return frozenset(member.value for member in cls)


@enum.unique
class EndpointAddr(enum.Enum):
ALERT_STREAM = 'ISAPI/Event/notification/alertStream'
Expand Down
2 changes: 2 additions & 0 deletions hikcamerabot/config/schemas/main_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
validates_schema,
)

from hikcamerabot.clients.hikvision.enums import AuthType
from hikcamerabot.config.schemas.validators import int_min_1, non_empty_str
from hikcamerabot.constants import (
CMD_CAM_ID_REGEX,
Expand Down Expand Up @@ -100,6 +101,7 @@ class Alert(Schema):
class CamAPIAuth(Schema):
user = f.Str(required=True, validate=non_empty_str)
password = f.Str(required=True, validate=non_empty_str)
type = f.Str(required=True, validate=v.OneOf(AuthType.choices()))


class CamAPI(Schema):
Expand Down
2 changes: 1 addition & 1 deletion hikcamerabot/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.6'
__version__ = '1.7'
22 changes: 22 additions & 0 deletions releases/release_1.7.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Release info

Version: 1.7

Release date: October 19, 2022

# Important
1. Add a new config variable to `config.json` for each of your cameras.

# New features
1. Added new authentication config variable `type` in `auth` section.
Could be one of `basic`, `digest`, or `digest_cached`. Default is `digest_cached`.
```json
"auth": {
"user": "dummy-user",
"password": "dummy-password",
"type": "digest_cached"
}
```

# Misc
N/A

0 comments on commit 6242f3a

Please sign in to comment.