* Refactor to use ids in data class * Use station_id * Refactor Netatmo to use oauth * Remove old code * Clean up * Clean up * Clean up * Refactor binary sensor * Add initial light implementation * Add discovery * Add set schedule service back in * Add discovery via homekit * More work on the light * Fix set schedule service * Clean up * Remove unnecessary code * Add support for multiple entities/accounts * Fix MANUFACTURER typo * Remove multiline inline if statement * Only add tags when camera type is welcome * Remove on/off as it's currently broken * Fix camera turn_on/off * Fix debug message * Refactor some camera code * Refactor camera methods * Remove old code * Rename method * Update persons regularly * Remove unused code * Refactor method * Fix isort * Add english strings * Catch NoDevice exception * Fix unique id and only add sensors for tags if present * Address comments * Remove ToDo comment * Add set_light_auto back in * Add debug info * Fix multiple camera issue * Move camera light service to camera * Only allow camera entities * Make test pass * Upgrade pyatmo module to 3.2.0 * Update requirements * Remove list comprehension * Remove guideline violating code * Remove stale code * Rename devices to entities * Remove light platform * Remove commented code * Exclude files from coverage * Remove unused code * Fix unique id * Address comments * Fix comments * Exclude sensor as well * Add another test * Use core interfaces
87 lines
2.3 KiB
Python
87 lines
2.3 KiB
Python
"""The Netatmo integration."""
|
|
import asyncio
|
|
import logging
|
|
|
|
import voluptuous as vol
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers import config_entry_oauth2_flow, config_validation as cv
|
|
|
|
from . import api, config_flow
|
|
from .const import AUTH, DATA_PERSONS, DOMAIN, OAUTH2_AUTHORIZE, OAUTH2_TOKEN
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
CONFIG_SCHEMA = vol.Schema(
|
|
{
|
|
DOMAIN: vol.Schema(
|
|
{
|
|
vol.Required(CONF_CLIENT_ID): cv.string,
|
|
vol.Required(CONF_CLIENT_SECRET): cv.string,
|
|
}
|
|
)
|
|
},
|
|
extra=vol.ALLOW_EXTRA,
|
|
)
|
|
|
|
PLATFORMS = ["binary_sensor", "camera", "climate", "sensor"]
|
|
|
|
|
|
async def async_setup(hass: HomeAssistant, config: dict):
|
|
"""Set up the Netatmo component."""
|
|
hass.data[DOMAIN] = {}
|
|
hass.data[DOMAIN][DATA_PERSONS] = {}
|
|
|
|
if DOMAIN not in config:
|
|
return True
|
|
|
|
config_flow.NetatmoFlowHandler.async_register_implementation(
|
|
hass,
|
|
config_entry_oauth2_flow.LocalOAuth2Implementation(
|
|
hass,
|
|
DOMAIN,
|
|
config[DOMAIN][CONF_CLIENT_ID],
|
|
config[DOMAIN][CONF_CLIENT_SECRET],
|
|
OAUTH2_AUTHORIZE,
|
|
OAUTH2_TOKEN,
|
|
),
|
|
)
|
|
|
|
return True
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|
"""Set up Netatmo from a config entry."""
|
|
implementation = await config_entry_oauth2_flow.async_get_config_entry_implementation(
|
|
hass, entry
|
|
)
|
|
|
|
hass.data[DOMAIN][entry.entry_id] = {
|
|
AUTH: api.ConfigEntryNetatmoAuth(hass, entry, implementation)
|
|
}
|
|
|
|
for component in PLATFORMS:
|
|
hass.async_create_task(
|
|
hass.config_entries.async_forward_entry_setup(entry, component)
|
|
)
|
|
|
|
return True
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|
"""Unload a config entry."""
|
|
unload_ok = all(
|
|
await asyncio.gather(
|
|
*[
|
|
hass.config_entries.async_forward_entry_unload(entry, component)
|
|
for component in PLATFORMS
|
|
]
|
|
)
|
|
)
|
|
if unload_ok:
|
|
hass.data[DOMAIN].pop(entry.entry_id)
|
|
|
|
return unload_ok
|