-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
configuration.py
31 lines (24 loc) · 892 Bytes
/
configuration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""Python library to enable Axis devices to integrate with Home Assistant."""
import attr
import requests
from requests.auth import HTTPDigestAuth
@attr.s
class Configuration:
"""Device configuration."""
host: str = attr.ib()
username: str = attr.ib(kw_only=True)
password: str = attr.ib(kw_only=True)
port: int = attr.ib(default=80, kw_only=True)
web_proto: str = attr.ib(default="http", kw_only=True)
verify_ssl: bool = attr.ib(default=False, kw_only=True)
session: requests.Session = attr.ib()
@session.default
def prepare_session(self):
session = requests.Session()
session.auth = HTTPDigestAuth(self.username, self.password)
session.verify = self.verify_ssl
return session
@property
def url(self):
"""Represent device base url."""
return f"{self.web_proto}://{self.host}:{self.port}"