-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
executable file
·58 lines (45 loc) · 2.09 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
48
49
50
51
52
53
54
55
56
57
58
"""The Toshiba AC integration."""
from __future__ import annotations
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_ID, CONF_NAME, Platform
from homeassistant.core import HomeAssistant
from homeassistant.components.climate import (
PLATFORM_SCHEMA,
)
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from .const import DOMAIN, CONF_IP, CONF_LOCAL_KEY
import voluptuous as vol
DEFAULT_NAME = "Toshiba AC - Climate"
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_ID): cv.string,
vol.Required(CONF_IP): cv.string,
vol.Required(CONF_LOCAL_KEY): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
}
)
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Toshiba AC from a config entry."""
# TODO Optionally store an object for your platforms to access
# hass.data[DOMAIN][entry.entry_id] = ...
# TODO Optionally validate config entry options before setting up platform
hass.config_entries.async_setup_platforms(
entry, (Platform.CLIMATE, Platform.SENSOR)
)
# hass.helpers.discovery.load_platform("climate", DOMAIN, {}, entry)
# TODO Remove if the integration does not have an options flow
entry.async_on_unload(entry.add_update_listener(config_entry_update_listener))
return True
# TODO Remove if the integration does not have an options flow
async def config_entry_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Update listener, called when the config entry options are changed."""
await hass.config_entries.async_reload(entry.entry_id)
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
if unload_ok := await hass.config_entries.async_unload_platforms(
entry, (Platform.CLIMATE, Platform.SENSOR)
):
hass.data[DOMAIN].pop(entry.entry_id)
return unload_ok