Remove global variable from bloomsky (#33720)
This commit is contained in:
parent
b1326928df
commit
983ed8b8b4
4 changed files with 17 additions and 12 deletions
|
@ -13,7 +13,6 @@ from homeassistant.util import Throttle
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
BLOOMSKY = None
|
|
||||||
BLOOMSKY_TYPE = ["camera", "binary_sensor", "sensor"]
|
BLOOMSKY_TYPE = ["camera", "binary_sensor", "sensor"]
|
||||||
|
|
||||||
DOMAIN = "bloomsky"
|
DOMAIN = "bloomsky"
|
||||||
|
@ -31,12 +30,14 @@ def setup(hass, config):
|
||||||
"""Set up the BloomSky component."""
|
"""Set up the BloomSky component."""
|
||||||
api_key = config[DOMAIN][CONF_API_KEY]
|
api_key = config[DOMAIN][CONF_API_KEY]
|
||||||
|
|
||||||
global BLOOMSKY # pylint: disable=global-statement
|
bloomsky = None
|
||||||
try:
|
try:
|
||||||
BLOOMSKY = BloomSky(api_key, hass.config.units.is_metric)
|
bloomsky = BloomSky(api_key, hass.config.units.is_metric)
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
hass.data[DOMAIN] = bloomsky
|
||||||
|
|
||||||
for component in BLOOMSKY_TYPE:
|
for component in BLOOMSKY_TYPE:
|
||||||
discovery.load_platform(hass, component, DOMAIN, {}, config)
|
discovery.load_platform(hass, component, DOMAIN, {}, config)
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensor
|
||||||
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
|
from . import DOMAIN
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -26,10 +26,11 @@ 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."""
|
||||||
# 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)
|
||||||
|
bloomsky = hass.data[DOMAIN]
|
||||||
|
|
||||||
for device in BLOOMSKY.devices.values():
|
for device in bloomsky.devices.values():
|
||||||
for variable in sensors:
|
for variable in sensors:
|
||||||
add_entities([BloomSkySensor(BLOOMSKY, device, variable)], True)
|
add_entities([BloomSkySensor(bloomsky, device, variable)], True)
|
||||||
|
|
||||||
|
|
||||||
class BloomSkySensor(BinarySensorDevice):
|
class BloomSkySensor(BinarySensorDevice):
|
||||||
|
|
|
@ -5,13 +5,15 @@ import requests
|
||||||
|
|
||||||
from homeassistant.components.camera import Camera
|
from homeassistant.components.camera import Camera
|
||||||
|
|
||||||
from . import BLOOMSKY
|
from . import DOMAIN
|
||||||
|
|
||||||
|
|
||||||
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."""
|
||||||
for device in BLOOMSKY.devices.values():
|
bloomsky = hass.data[DOMAIN]
|
||||||
add_entities([BloomSkyCamera(BLOOMSKY, device)])
|
|
||||||
|
for device in bloomsky.devices.values():
|
||||||
|
add_entities([BloomSkyCamera(bloomsky, device)])
|
||||||
|
|
||||||
|
|
||||||
class BloomSkyCamera(Camera):
|
class BloomSkyCamera(Camera):
|
||||||
|
|
|
@ -13,7 +13,7 @@ from homeassistant.const import (
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
from . import BLOOMSKY
|
from . import DOMAIN
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -61,10 +61,11 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the available BloomSky weather sensors."""
|
"""Set up the available BloomSky weather sensors."""
|
||||||
# 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)
|
||||||
|
bloomsky = hass.data[DOMAIN]
|
||||||
|
|
||||||
for device in BLOOMSKY.devices.values():
|
for device in bloomsky.devices.values():
|
||||||
for variable in sensors:
|
for variable in sensors:
|
||||||
add_entities([BloomSkySensor(BLOOMSKY, device, variable)], True)
|
add_entities([BloomSkySensor(bloomsky, device, variable)], True)
|
||||||
|
|
||||||
|
|
||||||
class BloomSkySensor(Entity):
|
class BloomSkySensor(Entity):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue