Fix unnecessary hass.components interaction (#23029)
* Fix wemo * Fix bloomsky * Fix netatmo * Fix one more reference
This commit is contained in:
parent
57f17707c6
commit
c94b031db1
11 changed files with 41 additions and 33 deletions
|
@ -8,6 +8,8 @@ from homeassistant.components.binary_sensor import (
|
||||||
from homeassistant.const import CONF_MONITORED_CONDITIONS
|
from homeassistant.const import CONF_MONITORED_CONDITIONS
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
|
from . import BLOOMSKY
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEPENDENCIES = ['bloomsky']
|
DEPENDENCIES = ['bloomsky']
|
||||||
|
@ -25,14 +27,13 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the available BloomSky weather binary sensors."""
|
"""Set up the available BloomSky weather binary sensors."""
|
||||||
bloomsky = hass.components.bloomsky
|
|
||||||
# Default needed in case of discovery
|
# Default needed in case of discovery
|
||||||
sensors = config.get(CONF_MONITORED_CONDITIONS, SENSOR_TYPES)
|
sensors = config.get(CONF_MONITORED_CONDITIONS, SENSOR_TYPES)
|
||||||
|
|
||||||
for device in bloomsky.BLOOMSKY.devices.values():
|
for device in BLOOMSKY.devices.values():
|
||||||
for variable in sensors:
|
for variable in sensors:
|
||||||
add_entities(
|
add_entities(
|
||||||
[BloomSkySensor(bloomsky.BLOOMSKY, device, variable)], True)
|
[BloomSkySensor(BLOOMSKY, device, variable)], True)
|
||||||
|
|
||||||
|
|
||||||
class BloomSkySensor(BinarySensorDevice):
|
class BloomSkySensor(BinarySensorDevice):
|
||||||
|
|
|
@ -5,14 +5,15 @@ import requests
|
||||||
|
|
||||||
from homeassistant.components.camera import Camera
|
from homeassistant.components.camera import Camera
|
||||||
|
|
||||||
|
from . import BLOOMSKY
|
||||||
|
|
||||||
DEPENDENCIES = ['bloomsky']
|
DEPENDENCIES = ['bloomsky']
|
||||||
|
|
||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up access to BloomSky cameras."""
|
"""Set up access to BloomSky cameras."""
|
||||||
bloomsky = hass.components.bloomsky
|
for device in BLOOMSKY.devices.values():
|
||||||
for device in bloomsky.BLOOMSKY.devices.values():
|
add_entities([BloomSkyCamera(BLOOMSKY, device)])
|
||||||
add_entities([BloomSkyCamera(bloomsky.BLOOMSKY, device)])
|
|
||||||
|
|
||||||
|
|
||||||
class BloomSkyCamera(Camera):
|
class BloomSkyCamera(Camera):
|
||||||
|
|
|
@ -8,7 +8,9 @@ from homeassistant.const import (TEMP_FAHRENHEIT, CONF_MONITORED_CONDITIONS)
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
from . import BLOOMSKY
|
||||||
|
|
||||||
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
DEPENDENCIES = ['bloomsky']
|
DEPENDENCIES = ['bloomsky']
|
||||||
|
|
||||||
|
@ -38,14 +40,13 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the available BloomSky weather sensors."""
|
"""Set up the available BloomSky weather sensors."""
|
||||||
bloomsky = hass.components.bloomsky
|
|
||||||
# Default needed in case of discovery
|
# Default needed in case of discovery
|
||||||
sensors = config.get(CONF_MONITORED_CONDITIONS, SENSOR_TYPES)
|
sensors = config.get(CONF_MONITORED_CONDITIONS, SENSOR_TYPES)
|
||||||
|
|
||||||
for device in bloomsky.BLOOMSKY.devices.values():
|
for device in BLOOMSKY.devices.values():
|
||||||
for variable in sensors:
|
for variable in sensors:
|
||||||
add_entities(
|
add_entities(
|
||||||
[BloomSkySensor(bloomsky.BLOOMSKY, device, variable)], True)
|
[BloomSkySensor(BLOOMSKY, device, variable)], True)
|
||||||
|
|
||||||
|
|
||||||
class BloomSkySensor(Entity):
|
class BloomSkySensor(Entity):
|
||||||
|
|
|
@ -8,7 +8,7 @@ from homeassistant.components.binary_sensor import (
|
||||||
from homeassistant.const import CONF_TIMEOUT
|
from homeassistant.const import CONF_TIMEOUT
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
|
|
||||||
from . import CameraData
|
from . import CameraData, NETATMO_AUTH
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -53,7 +53,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the access to Netatmo binary sensor."""
|
"""Set up the access to Netatmo binary sensor."""
|
||||||
netatmo = hass.components.netatmo
|
|
||||||
home = config.get(CONF_HOME)
|
home = config.get(CONF_HOME)
|
||||||
timeout = config.get(CONF_TIMEOUT)
|
timeout = config.get(CONF_TIMEOUT)
|
||||||
if timeout is None:
|
if timeout is None:
|
||||||
|
@ -63,7 +62,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
|
|
||||||
import pyatmo
|
import pyatmo
|
||||||
try:
|
try:
|
||||||
data = CameraData(hass, netatmo.NETATMO_AUTH, home)
|
data = CameraData(hass, NETATMO_AUTH, home)
|
||||||
if not data.get_camera_names():
|
if not data.get_camera_names():
|
||||||
return None
|
return None
|
||||||
except pyatmo.NoDevice:
|
except pyatmo.NoDevice:
|
||||||
|
|
|
@ -9,7 +9,7 @@ from homeassistant.components.camera import (
|
||||||
from homeassistant.const import CONF_VERIFY_SSL
|
from homeassistant.const import CONF_VERIFY_SSL
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
|
|
||||||
from . import CameraData
|
from . import CameraData, NETATMO_AUTH
|
||||||
|
|
||||||
DEPENDENCIES = ['netatmo']
|
DEPENDENCIES = ['netatmo']
|
||||||
|
|
||||||
|
@ -35,13 +35,12 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up access to Netatmo cameras."""
|
"""Set up access to Netatmo cameras."""
|
||||||
netatmo = hass.components.netatmo
|
|
||||||
home = config.get(CONF_HOME)
|
home = config.get(CONF_HOME)
|
||||||
verify_ssl = config.get(CONF_VERIFY_SSL, True)
|
verify_ssl = config.get(CONF_VERIFY_SSL, True)
|
||||||
quality = config.get(CONF_QUALITY, DEFAULT_QUALITY)
|
quality = config.get(CONF_QUALITY, DEFAULT_QUALITY)
|
||||||
import pyatmo
|
import pyatmo
|
||||||
try:
|
try:
|
||||||
data = CameraData(hass, netatmo.NETATMO_AUTH, home)
|
data = CameraData(hass, NETATMO_AUTH, home)
|
||||||
for camera_name in data.get_camera_names():
|
for camera_name in data.get_camera_names():
|
||||||
camera_type = data.get_camera_type(camera=camera_name, home=home)
|
camera_type = data.get_camera_type(camera=camera_name, home=home)
|
||||||
if CONF_CAMERAS in config:
|
if CONF_CAMERAS in config:
|
||||||
|
|
|
@ -14,6 +14,8 @@ from homeassistant.const import (
|
||||||
STATE_OFF, TEMP_CELSIUS, ATTR_TEMPERATURE, CONF_NAME)
|
STATE_OFF, TEMP_CELSIUS, ATTR_TEMPERATURE, CONF_NAME)
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
|
|
||||||
|
from . import NETATMO_AUTH
|
||||||
|
|
||||||
DEPENDENCIES = ['netatmo']
|
DEPENDENCIES = ['netatmo']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -66,12 +68,10 @@ NA_VALVE = 'NRV'
|
||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the NetAtmo Thermostat."""
|
"""Set up the NetAtmo Thermostat."""
|
||||||
netatmo = hass.components.netatmo
|
|
||||||
|
|
||||||
import pyatmo
|
import pyatmo
|
||||||
homes_conf = config.get(CONF_HOMES)
|
homes_conf = config.get(CONF_HOMES)
|
||||||
try:
|
try:
|
||||||
home_data = HomeData(netatmo.NETATMO_AUTH)
|
home_data = HomeData(NETATMO_AUTH)
|
||||||
except pyatmo.NoDevice:
|
except pyatmo.NoDevice:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
for home in homes:
|
for home in homes:
|
||||||
_LOGGER.debug("Setting up %s ...", home)
|
_LOGGER.debug("Setting up %s ...", home)
|
||||||
try:
|
try:
|
||||||
room_data = ThermostatData(netatmo.NETATMO_AUTH, home)
|
room_data = ThermostatData(NETATMO_AUTH, home)
|
||||||
except pyatmo.NoDevice:
|
except pyatmo.NoDevice:
|
||||||
continue
|
continue
|
||||||
for room_id in room_data.get_room_ids():
|
for room_id in room_data.get_room_ids():
|
||||||
|
|
|
@ -12,6 +12,8 @@ from homeassistant.const import (
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
|
from . import NETATMO_AUTH
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
CONF_MODULES = 'modules'
|
CONF_MODULES = 'modules'
|
||||||
|
@ -67,26 +69,24 @@ MODULE_TYPE_INDOOR = 'NAModule4'
|
||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the available Netatmo weather sensors."""
|
"""Set up the available Netatmo weather sensors."""
|
||||||
netatmo = hass.components.netatmo
|
|
||||||
|
|
||||||
dev = []
|
dev = []
|
||||||
if CONF_MODULES in config:
|
if CONF_MODULES in config:
|
||||||
manual_config(netatmo, config, dev)
|
manual_config(config, dev)
|
||||||
else:
|
else:
|
||||||
auto_config(netatmo, config, dev)
|
auto_config(config, dev)
|
||||||
|
|
||||||
if dev:
|
if dev:
|
||||||
add_entities(dev, True)
|
add_entities(dev, True)
|
||||||
|
|
||||||
|
|
||||||
def manual_config(netatmo, config, dev):
|
def manual_config(config, dev):
|
||||||
"""Handle manual configuration."""
|
"""Handle manual configuration."""
|
||||||
import pyatmo
|
import pyatmo
|
||||||
|
|
||||||
all_classes = all_product_classes()
|
all_classes = all_product_classes()
|
||||||
not_handled = {}
|
not_handled = {}
|
||||||
for data_class in all_classes:
|
for data_class in all_classes:
|
||||||
data = NetAtmoData(netatmo.NETATMO_AUTH, data_class,
|
data = NetAtmoData(NETATMO_AUTH, data_class,
|
||||||
config.get(CONF_STATION))
|
config.get(CONF_STATION))
|
||||||
try:
|
try:
|
||||||
# Iterate each module
|
# Iterate each module
|
||||||
|
@ -109,13 +109,12 @@ def manual_config(netatmo, config, dev):
|
||||||
_LOGGER.error('Module name: "%s" not found', module_name)
|
_LOGGER.error('Module name: "%s" not found', module_name)
|
||||||
|
|
||||||
|
|
||||||
def auto_config(netatmo, config, dev):
|
def auto_config(config, dev):
|
||||||
"""Handle auto configuration."""
|
"""Handle auto configuration."""
|
||||||
import pyatmo
|
import pyatmo
|
||||||
|
|
||||||
for data_class in all_product_classes():
|
for data_class in all_product_classes():
|
||||||
data = NetAtmoData(netatmo.NETATMO_AUTH, data_class,
|
data = NetAtmoData(NETATMO_AUTH, data_class, config.get(CONF_STATION))
|
||||||
config.get(CONF_STATION))
|
|
||||||
try:
|
try:
|
||||||
for module_name in data.get_module_names():
|
for module_name in data.get_module_names():
|
||||||
for variable in \
|
for variable in \
|
||||||
|
|
|
@ -8,6 +8,8 @@ import requests
|
||||||
from homeassistant.components.binary_sensor import BinarySensorDevice
|
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||||
from homeassistant.exceptions import PlatformNotReady
|
from homeassistant.exceptions import PlatformNotReady
|
||||||
|
|
||||||
|
from . import SUBSCRIPTION_REGISTRY
|
||||||
|
|
||||||
DEPENDENCIES = ['wemo']
|
DEPENDENCIES = ['wemo']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -66,7 +68,7 @@ class WemoBinarySensor(BinarySensorDevice):
|
||||||
# Define inside async context so we know our event loop
|
# Define inside async context so we know our event loop
|
||||||
self._update_lock = asyncio.Lock()
|
self._update_lock = asyncio.Lock()
|
||||||
|
|
||||||
registry = self.hass.components.wemo.SUBSCRIPTION_REGISTRY
|
registry = SUBSCRIPTION_REGISTRY
|
||||||
await self.hass.async_add_executor_job(registry.register, self.wemo)
|
await self.hass.async_add_executor_job(registry.register, self.wemo)
|
||||||
registry.on(self.wemo, None, self._subscription_callback)
|
registry.on(self.wemo, None, self._subscription_callback)
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,8 @@ from homeassistant.components.fan import (
|
||||||
from homeassistant.exceptions import PlatformNotReady
|
from homeassistant.exceptions import PlatformNotReady
|
||||||
from homeassistant.const import ATTR_ENTITY_ID
|
from homeassistant.const import ATTR_ENTITY_ID
|
||||||
|
|
||||||
|
from . import SUBSCRIPTION_REGISTRY
|
||||||
|
|
||||||
DEPENDENCIES = ['wemo']
|
DEPENDENCIES = ['wemo']
|
||||||
SCAN_INTERVAL = timedelta(seconds=10)
|
SCAN_INTERVAL = timedelta(seconds=10)
|
||||||
DATA_KEY = 'fan.wemo'
|
DATA_KEY = 'fan.wemo'
|
||||||
|
@ -229,7 +231,7 @@ class WemoHumidifier(FanEntity):
|
||||||
# Define inside async context so we know our event loop
|
# Define inside async context so we know our event loop
|
||||||
self._update_lock = asyncio.Lock()
|
self._update_lock = asyncio.Lock()
|
||||||
|
|
||||||
registry = self.hass.components.wemo.SUBSCRIPTION_REGISTRY
|
registry = SUBSCRIPTION_REGISTRY
|
||||||
await self.hass.async_add_executor_job(registry.register, self.wemo)
|
await self.hass.async_add_executor_job(registry.register, self.wemo)
|
||||||
registry.on(self.wemo, None, self._subscription_callback)
|
registry.on(self.wemo, None, self._subscription_callback)
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,8 @@ from homeassistant.components.light import (
|
||||||
from homeassistant.exceptions import PlatformNotReady
|
from homeassistant.exceptions import PlatformNotReady
|
||||||
import homeassistant.util.color as color_util
|
import homeassistant.util.color as color_util
|
||||||
|
|
||||||
|
from . import SUBSCRIPTION_REGISTRY
|
||||||
|
|
||||||
DEPENDENCIES = ['wemo']
|
DEPENDENCIES = ['wemo']
|
||||||
|
|
||||||
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
||||||
|
@ -226,7 +228,7 @@ class WemoDimmer(Light):
|
||||||
# Define inside async context so we know our event loop
|
# Define inside async context so we know our event loop
|
||||||
self._update_lock = asyncio.Lock()
|
self._update_lock = asyncio.Lock()
|
||||||
|
|
||||||
registry = self.hass.components.wemo.SUBSCRIPTION_REGISTRY
|
registry = SUBSCRIPTION_REGISTRY
|
||||||
await self.hass.async_add_executor_job(registry.register, self.wemo)
|
await self.hass.async_add_executor_job(registry.register, self.wemo)
|
||||||
registry.on(self.wemo, None, self._subscription_callback)
|
registry.on(self.wemo, None, self._subscription_callback)
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@ from homeassistant.util import convert
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
STATE_OFF, STATE_ON, STATE_STANDBY, STATE_UNKNOWN)
|
STATE_OFF, STATE_ON, STATE_STANDBY, STATE_UNKNOWN)
|
||||||
|
|
||||||
|
from . import SUBSCRIPTION_REGISTRY
|
||||||
|
|
||||||
DEPENDENCIES = ['wemo']
|
DEPENDENCIES = ['wemo']
|
||||||
SCAN_INTERVAL = timedelta(seconds=10)
|
SCAN_INTERVAL = timedelta(seconds=10)
|
||||||
|
|
||||||
|
@ -198,7 +200,7 @@ class WemoSwitch(SwitchDevice):
|
||||||
# Define inside async context so we know our event loop
|
# Define inside async context so we know our event loop
|
||||||
self._update_lock = asyncio.Lock()
|
self._update_lock = asyncio.Lock()
|
||||||
|
|
||||||
registry = self.hass.components.wemo.SUBSCRIPTION_REGISTRY
|
registry = SUBSCRIPTION_REGISTRY
|
||||||
await self.hass.async_add_job(registry.register, self.wemo)
|
await self.hass.async_add_job(registry.register, self.wemo)
|
||||||
registry.on(self.wemo, None, self._subscription_callback)
|
registry.on(self.wemo, None, self._subscription_callback)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue