Home Assistant Unofficial Reference 2024.12.1
config.py
Go to the documentation of this file.
1 """Axis network device abstraction."""
2 
3 from __future__ import annotations
4 
5 from dataclasses import dataclass
6 from typing import Self
7 
8 from homeassistant.config_entries import ConfigEntry
9 from homeassistant.const import (
10  CONF_HOST,
11  CONF_MODEL,
12  CONF_NAME,
13  CONF_PASSWORD,
14  CONF_PORT,
15  CONF_PROTOCOL,
16  CONF_TRIGGER_TIME,
17  CONF_USERNAME,
18 )
19 
20 from ..const import (
21  CONF_STREAM_PROFILE,
22  CONF_VIDEO_SOURCE,
23  DEFAULT_STREAM_PROFILE,
24  DEFAULT_TRIGGER_TIME,
25  DEFAULT_VIDEO_SOURCE,
26 )
27 
28 
29 @dataclass
30 class AxisConfig:
31  """Represent a Axis config entry."""
32 
33  entry: ConfigEntry
34 
35  protocol: str
36  host: str
37  port: int
38  username: str
39  password: str
40  model: str
41  name: str
42 
43  # Options
44 
45  stream_profile: str
46  """Option defining what stream profile camera platform should use."""
47  trigger_time: int
48  """Option defining minimum number of seconds to keep trigger high."""
49  video_source: str
50  """Option defining what video source camera platform should use."""
51 
52  @classmethod
53  def from_config_entry(cls, config_entry: ConfigEntry) -> Self:
54  """Create object from config entry."""
55  config = config_entry.data
56  options = config_entry.options
57  return cls(
58  entry=config_entry,
59  protocol=config.get(CONF_PROTOCOL, "http"),
60  host=config[CONF_HOST],
61  username=config[CONF_USERNAME],
62  password=config[CONF_PASSWORD],
63  port=config[CONF_PORT],
64  model=config[CONF_MODEL],
65  name=config[CONF_NAME],
66  stream_profile=options.get(CONF_STREAM_PROFILE, DEFAULT_STREAM_PROFILE),
67  trigger_time=options.get(CONF_TRIGGER_TIME, DEFAULT_TRIGGER_TIME),
68  video_source=options.get(CONF_VIDEO_SOURCE, DEFAULT_VIDEO_SOURCE),
69  )
Self from_config_entry(cls, ConfigEntry config_entry)
Definition: config.py:53