Home Assistant Unofficial Reference 2024.12.1
config.py
Go to the documentation of this file.
1 """deCONZ config entry 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 CONF_API_KEY, CONF_HOST, CONF_PORT
10 
11 from ..const import (
12  CONF_ALLOW_CLIP_SENSOR,
13  CONF_ALLOW_DECONZ_GROUPS,
14  CONF_ALLOW_NEW_DEVICES,
15  DEFAULT_ALLOW_CLIP_SENSOR,
16  DEFAULT_ALLOW_DECONZ_GROUPS,
17  DEFAULT_ALLOW_NEW_DEVICES,
18 )
19 
20 
21 @dataclass
23  """Represent a deCONZ config entry."""
24 
25  entry: ConfigEntry
26 
27  host: str
28  port: int
29  api_key: str
30 
31  allow_clip_sensor: bool
32  allow_deconz_groups: bool
33  allow_new_devices: bool
34 
35  @classmethod
36  def from_config_entry(cls, config_entry: ConfigEntry) -> Self:
37  """Create object from config entry."""
38  config = config_entry.data
39  options = config_entry.options
40  return cls(
41  entry=config_entry,
42  host=config[CONF_HOST],
43  port=config[CONF_PORT],
44  api_key=config[CONF_API_KEY],
45  allow_clip_sensor=options.get(
46  CONF_ALLOW_CLIP_SENSOR,
47  DEFAULT_ALLOW_CLIP_SENSOR,
48  ),
49  allow_deconz_groups=options.get(
50  CONF_ALLOW_DECONZ_GROUPS,
51  DEFAULT_ALLOW_DECONZ_GROUPS,
52  ),
53  allow_new_devices=options.get(
54  CONF_ALLOW_NEW_DEVICES,
55  DEFAULT_ALLOW_NEW_DEVICES,
56  ),
57  )
Self from_config_entry(cls, ConfigEntry config_entry)
Definition: config.py:36