-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
47 lines (36 loc) · 1.44 KB
/
__init__.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""The MQTT Push Button integration."""
from __future__ import annotations
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
from .const import CONF_NAME, CONF_TOPIC, CONF_VALUE_TEMPLATE, DOMAIN
PLATFORMS: list[Platform] = [Platform.SENSOR]
type Data = dict[str, str, dr.DeviceEntry]
type MqttPushButtonConfigEntry = ConfigEntry[Data]
async def async_setup_entry(
hass: HomeAssistant, entry: MqttPushButtonConfigEntry
) -> bool:
"""Set up MQTT Push Button from a config entry."""
data: Data = {}
hass.data.setdefault(DOMAIN, data)
device_registry = dr.async_get(hass)
device = device_registry.async_get_or_create(
config_entry_id=entry.entry_id,
identifiers={(DOMAIN, entry.unique_id)},
name=entry.data[CONF_NAME],
)
hass.data[DOMAIN][entry.entry_id] = {
"name": entry.data[CONF_NAME],
"topic": entry.data[CONF_TOPIC],
"value_template": entry.data[CONF_VALUE_TEMPLATE],
"device": device,
}
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True
# TODO Update entry annotation
async def async_unload_entry(
hass: HomeAssistant, entry: MqttPushButtonConfigEntry
) -> bool:
"""Unload a config entry."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)