diff --git a/custom_components/badnest/__init__.py b/custom_components/badnest/__init__.py index 62c0902..8de517e 100644 --- a/custom_components/badnest/__init__.py +++ b/custom_components/badnest/__init__.py @@ -16,3 +16,17 @@ CONFIG_SCHEMA = vol.Schema( }, extra=vol.ALLOW_EXTRA, ) + + +def setup(hass, config): + """Set up the badnest component.""" + if config.get(DOMAIN) is not None: + email = config[DOMAIN].get(CONF_EMAIL) + password = config[DOMAIN].get(CONF_PASSWORD) + else: + email = None + password = None + + hass.data[DOMAIN] = {CONF_EMAIL: email, CONF_PASSWORD: password} + + return True diff --git a/custom_components/badnest/camera.py b/custom_components/badnest/camera.py index fb72232..2cca102 100644 --- a/custom_components/badnest/camera.py +++ b/custom_components/badnest/camera.py @@ -6,6 +6,7 @@ from homeassistant.util.dt import utcnow from homeassistant.components.camera import Camera, SUPPORT_ON_OFF from homeassistant.const import CONF_EMAIL, CONF_PASSWORD +from .api import NestCameraAPI from .const import DOMAIN @@ -19,12 +20,13 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): - """Set up a Foscam IP Camera.""" - from .api import NestCameraAPI - + """Set up a Nest Camera.""" hass.data[DATA_KEY] = dict() - api = NestCameraAPI(config.get(CONF_EMAIL), config.get(CONF_PASSWORD)) + api = NestCameraAPI( + hass.data[DOMAIN][CONF_EMAIL], + hass.data[DOMAIN][CONF_PASSWORD] + ) # cameras = await hass.async_add_executor_job(nest.get_cameras()) cameras = [] diff --git a/custom_components/badnest/climate.py b/custom_components/badnest/climate.py index d611d1e..5a1904e 100644 --- a/custom_components/badnest/climate.py +++ b/custom_components/badnest/climate.py @@ -29,6 +29,7 @@ from homeassistant.const import ( ) from .api import NestThermostatAPI +from .const import DOMAIN NEST_MODE_HEAT_COOL = "range" NEST_MODE_ECO = "eco" @@ -60,14 +61,17 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): - """Set up a Foscam IP Camera.""" - nest = NestThermostatAPI(config.get(CONF_EMAIL), config.get(CONF_PASSWORD)) + """Set up the Nest climate device.""" + nest = NestThermostatAPI( + hass.data[DOMAIN][CONF_EMAIL], + hass.data[DOMAIN][CONF_PASSWORD] + ) async_add_entities([ShittyNestClimate(nest)]) class ShittyNestClimate(ClimateDevice): - """Representation of a demo climate device.""" + """Representation of a Nest climate device.""" def __init__(self, api): """Initialize the thermostat."""