mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
commit
6532eae3d5
@ -1,13 +1,4 @@
|
|||||||
"""
|
"""Provides methods to bootstrap a home assistant instance."""
|
||||||
homeassistant.bootstrap
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
Provides methods to bootstrap a home assistant instance.
|
|
||||||
|
|
||||||
Each method will return a tuple (bus, statemachine).
|
|
||||||
|
|
||||||
After bootstrapping you can add your own components or
|
|
||||||
start by calling homeassistant.start_home_assistant(bus)
|
|
||||||
"""
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
@ -15,6 +6,7 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from threading import RLock
|
||||||
|
|
||||||
import homeassistant.components as core_components
|
import homeassistant.components as core_components
|
||||||
import homeassistant.components.group as group
|
import homeassistant.components.group as group
|
||||||
@ -32,6 +24,8 @@ from homeassistant.helpers import event_decorators, service
|
|||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
_SETUP_LOCK = RLock()
|
||||||
|
_CURRENT_SETUP = []
|
||||||
|
|
||||||
ATTR_COMPONENT = 'component'
|
ATTR_COMPONENT = 'component'
|
||||||
|
|
||||||
@ -79,10 +73,21 @@ def _handle_requirements(hass, component, name):
|
|||||||
|
|
||||||
def _setup_component(hass, domain, config):
|
def _setup_component(hass, domain, config):
|
||||||
"""Setup a component for Home Assistant."""
|
"""Setup a component for Home Assistant."""
|
||||||
|
# pylint: disable=too-many-return-statements
|
||||||
if domain in hass.config.components:
|
if domain in hass.config.components:
|
||||||
return True
|
return True
|
||||||
component = loader.get_component(domain)
|
|
||||||
|
|
||||||
|
with _SETUP_LOCK:
|
||||||
|
# It might have been loaded while waiting for lock
|
||||||
|
if domain in hass.config.components:
|
||||||
|
return True
|
||||||
|
|
||||||
|
if domain in _CURRENT_SETUP:
|
||||||
|
_LOGGER.error('Attempt made to setup %s during setup of %s',
|
||||||
|
domain, domain)
|
||||||
|
return False
|
||||||
|
|
||||||
|
component = loader.get_component(domain)
|
||||||
missing_deps = [dep for dep in getattr(component, 'DEPENDENCIES', [])
|
missing_deps = [dep for dep in getattr(component, 'DEPENDENCIES', [])
|
||||||
if dep not in hass.config.components]
|
if dep not in hass.config.components]
|
||||||
|
|
||||||
@ -95,6 +100,8 @@ def _setup_component(hass, domain, config):
|
|||||||
if not _handle_requirements(hass, component, domain):
|
if not _handle_requirements(hass, component, domain):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
_CURRENT_SETUP.append(domain)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not component.setup(hass, config):
|
if not component.setup(hass, config):
|
||||||
_LOGGER.error('component %s failed to initialize', domain)
|
_LOGGER.error('component %s failed to initialize', domain)
|
||||||
@ -102,6 +109,8 @@ def _setup_component(hass, domain, config):
|
|||||||
except Exception: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
_LOGGER.exception('Error during setup of component %s', domain)
|
_LOGGER.exception('Error during setup of component %s', domain)
|
||||||
return False
|
return False
|
||||||
|
finally:
|
||||||
|
_CURRENT_SETUP.remove(domain)
|
||||||
|
|
||||||
hass.config.components.append(component.DOMAIN)
|
hass.config.components.append(component.DOMAIN)
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ import logging
|
|||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.const import (STATE_ON, STATE_OFF)
|
from homeassistant.const import (STATE_ON, STATE_OFF)
|
||||||
from homeassistant.components import (mysensors, )
|
from homeassistant.components import (bloomsky, mysensors)
|
||||||
|
|
||||||
DOMAIN = 'binary_sensor'
|
DOMAIN = 'binary_sensor'
|
||||||
SCAN_INTERVAL = 30
|
SCAN_INTERVAL = 30
|
||||||
@ -32,6 +32,7 @@ SENSOR_CLASSES = [
|
|||||||
|
|
||||||
# Maps discovered services to their platforms
|
# Maps discovered services to their platforms
|
||||||
DISCOVERY_PLATFORMS = {
|
DISCOVERY_PLATFORMS = {
|
||||||
|
bloomsky.DISCOVER_BINARY_SENSORS: 'bloomsky',
|
||||||
mysensors.DISCOVER_BINARY_SENSORS: 'mysensors',
|
mysensors.DISCOVER_BINARY_SENSORS: 'mysensors',
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,19 +62,17 @@ class BinarySensorDevice(Entity):
|
|||||||
"""Return the state of the binary sensor."""
|
"""Return the state of the binary sensor."""
|
||||||
return STATE_ON if self.is_on else STATE_OFF
|
return STATE_ON if self.is_on else STATE_OFF
|
||||||
|
|
||||||
@property
|
|
||||||
def friendly_state(self):
|
|
||||||
"""Return the friendly state of the binary sensor."""
|
|
||||||
return None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def sensor_class(self):
|
def sensor_class(self):
|
||||||
"""Return the class of this sensor, from SENSOR_CASSES."""
|
"""Return the class of this sensor, from SENSOR_CLASSES."""
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def state_attributes(self):
|
||||||
"""Return device specific state attributes."""
|
"""Return device specific state attributes."""
|
||||||
return {
|
attr = {}
|
||||||
'sensor_class': self.sensor_class,
|
|
||||||
}
|
if self.sensor_class is not None:
|
||||||
|
attr['sensor_class'] = self.sensor_class
|
||||||
|
|
||||||
|
return attr
|
||||||
|
74
homeassistant/components/binary_sensor/bloomsky.py
Normal file
74
homeassistant/components/binary_sensor/bloomsky.py
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
"""
|
||||||
|
Support the binary sensors of a BloomSky weather station.
|
||||||
|
|
||||||
|
For more details about this component, please refer to the documentation at
|
||||||
|
https://home-assistant.io/components/binary_sensor.bloomsky/
|
||||||
|
"""
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||||
|
from homeassistant.loader import get_component
|
||||||
|
|
||||||
|
DEPENDENCIES = ["bloomsky"]
|
||||||
|
|
||||||
|
# These are the available sensors mapped to binary_sensor class
|
||||||
|
SENSOR_TYPES = {
|
||||||
|
"Rain": "moisture",
|
||||||
|
"Night": None,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
|
"""Set up the available BloomSky weather binary sensors."""
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
bloomsky = get_component('bloomsky')
|
||||||
|
sensors = config.get('monitored_conditions', SENSOR_TYPES)
|
||||||
|
|
||||||
|
for device in bloomsky.BLOOMSKY.devices.values():
|
||||||
|
for variable in sensors:
|
||||||
|
if variable in SENSOR_TYPES:
|
||||||
|
add_devices([BloomSkySensor(bloomsky.BLOOMSKY,
|
||||||
|
device,
|
||||||
|
variable)])
|
||||||
|
else:
|
||||||
|
logger.error("Cannot find definition for device: %s", variable)
|
||||||
|
|
||||||
|
|
||||||
|
class BloomSkySensor(BinarySensorDevice):
|
||||||
|
""" Represents a single binary sensor in a BloomSky device. """
|
||||||
|
|
||||||
|
def __init__(self, bs, device, sensor_name):
|
||||||
|
"""Initialize a bloomsky binary sensor."""
|
||||||
|
self._bloomsky = bs
|
||||||
|
self._device_id = device["DeviceID"]
|
||||||
|
self._sensor_name = sensor_name
|
||||||
|
self._name = "{} {}".format(device["DeviceName"], sensor_name)
|
||||||
|
self._unique_id = "bloomsky_binary_sensor {}".format(self._name)
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
"""The name of the BloomSky device and this sensor."""
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unique_id(self):
|
||||||
|
"""Unique ID for this sensor."""
|
||||||
|
return self._unique_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def sensor_class(self):
|
||||||
|
"""Return the class of this sensor, from SENSOR_CLASSES."""
|
||||||
|
return SENSOR_TYPES.get(self._sensor_name)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_on(self):
|
||||||
|
"""If binary sensor is on."""
|
||||||
|
return self._state
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
"""Request an update from the BloomSky API."""
|
||||||
|
self._bloomsky.refresh_devices()
|
||||||
|
|
||||||
|
self._state = \
|
||||||
|
self._bloomsky.devices[self._device_id]["Data"][self._sensor_name]
|
@ -11,6 +11,7 @@ from datetime import timedelta
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
from homeassistant.components import discovery
|
||||||
from homeassistant.const import CONF_API_KEY
|
from homeassistant.const import CONF_API_KEY
|
||||||
from homeassistant.helpers import validate_config
|
from homeassistant.helpers import validate_config
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
@ -24,6 +25,10 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
# no point in polling the API more frequently
|
# no point in polling the API more frequently
|
||||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=300)
|
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=300)
|
||||||
|
|
||||||
|
DISCOVER_SENSORS = 'bloomsky.sensors'
|
||||||
|
DISCOVER_BINARY_SENSORS = 'bloomsky.binary_sensor'
|
||||||
|
DISCOVER_CAMERAS = 'bloomsky.camera'
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=unused-argument,too-few-public-methods
|
# pylint: disable=unused-argument,too-few-public-methods
|
||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
@ -42,6 +47,12 @@ def setup(hass, config):
|
|||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
for component, discovery_service in (
|
||||||
|
('camera', DISCOVER_CAMERAS), ('sensor', DISCOVER_SENSORS),
|
||||||
|
('binary_sensor', DISCOVER_BINARY_SENSORS)):
|
||||||
|
discovery.discover(hass, discovery_service, component=component,
|
||||||
|
hass_config=config)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import requests
|
|||||||
|
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
|
from homeassistant.components import bloomsky
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_PICTURE,
|
ATTR_ENTITY_PICTURE,
|
||||||
HTTP_NOT_FOUND,
|
HTTP_NOT_FOUND,
|
||||||
@ -26,7 +27,9 @@ SCAN_INTERVAL = 30
|
|||||||
ENTITY_ID_FORMAT = DOMAIN + '.{}'
|
ENTITY_ID_FORMAT = DOMAIN + '.{}'
|
||||||
|
|
||||||
# Maps discovered services to their platforms
|
# Maps discovered services to their platforms
|
||||||
DISCOVERY_PLATFORMS = {}
|
DISCOVERY_PLATFORMS = {
|
||||||
|
bloomsky.DISCOVER_CAMERAS: 'bloomsky',
|
||||||
|
}
|
||||||
|
|
||||||
STATE_RECORDING = 'recording'
|
STATE_RECORDING = 'recording'
|
||||||
STATE_STREAMING = 'streaming'
|
STATE_STREAMING = 'streaming'
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
"""
|
"""
|
||||||
homeassistant.components.discovery
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
Starts a service to scan in intervals for new devices.
|
Starts a service to scan in intervals for new devices.
|
||||||
|
|
||||||
Will emit EVENT_PLATFORM_DISCOVERED whenever a new service has been discovered.
|
Will emit EVENT_PLATFORM_DISCOVERED whenever a new service has been discovered.
|
||||||
@ -39,24 +37,41 @@ SERVICE_HANDLERS = {
|
|||||||
|
|
||||||
|
|
||||||
def listen(hass, service, callback):
|
def listen(hass, service, callback):
|
||||||
"""
|
"""Setup listener for discovery of specific service.
|
||||||
Setup listener for discovery of specific service.
|
|
||||||
Service can be a string or a list/tuple.
|
Service can be a string or a list/tuple.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if isinstance(service, str):
|
if isinstance(service, str):
|
||||||
service = (service,)
|
service = (service,)
|
||||||
else:
|
else:
|
||||||
service = tuple(service)
|
service = tuple(service)
|
||||||
|
|
||||||
def discovery_event_listener(event):
|
def discovery_event_listener(event):
|
||||||
""" Listens for discovery events. """
|
"""Listen for discovery events."""
|
||||||
if event.data[ATTR_SERVICE] in service:
|
if event.data[ATTR_SERVICE] in service:
|
||||||
callback(event.data[ATTR_SERVICE], event.data[ATTR_DISCOVERED])
|
callback(event.data[ATTR_SERVICE], event.data.get(ATTR_DISCOVERED))
|
||||||
|
|
||||||
hass.bus.listen(EVENT_PLATFORM_DISCOVERED, discovery_event_listener)
|
hass.bus.listen(EVENT_PLATFORM_DISCOVERED, discovery_event_listener)
|
||||||
|
|
||||||
|
|
||||||
|
def discover(hass, service, discovered=None, component=None, hass_config=None):
|
||||||
|
"""Fire discovery event.
|
||||||
|
|
||||||
|
Can ensure a component is loaded.
|
||||||
|
"""
|
||||||
|
if component is not None:
|
||||||
|
bootstrap.setup_component(hass, component, hass_config)
|
||||||
|
|
||||||
|
data = {
|
||||||
|
ATTR_SERVICE: service
|
||||||
|
}
|
||||||
|
|
||||||
|
if discovered is not None:
|
||||||
|
data[ATTR_DISCOVERED] = discovered
|
||||||
|
|
||||||
|
hass.bus.fire(EVENT_PLATFORM_DISCOVERED, data)
|
||||||
|
|
||||||
|
|
||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
""" Starts a discovery service. """
|
""" Starts a discovery service. """
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
""" DO NOT MODIFY. Auto-generated by build_frontend script """
|
""" DO NOT MODIFY. Auto-generated by build_frontend script """
|
||||||
VERSION = "4ae370eaaad6bc779d08713b79ce3cba"
|
VERSION = "72a593fc8887c08d6f4ad9bd483bd232"
|
||||||
|
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
|||||||
Subproject commit 4cdefac2fe6f016fa09d872c8cb062ba01442b08
|
Subproject commit 40ff847f2d0670367a2fd29e3340a4f94ab1ff49
|
@ -10,7 +10,7 @@ import logging
|
|||||||
|
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.components import (
|
from homeassistant.components import (
|
||||||
wink, zwave, isy994, verisure, ecobee, tellduslive, mysensors)
|
wink, zwave, isy994, verisure, ecobee, tellduslive, mysensors, bloomsky)
|
||||||
|
|
||||||
DOMAIN = 'sensor'
|
DOMAIN = 'sensor'
|
||||||
SCAN_INTERVAL = 30
|
SCAN_INTERVAL = 30
|
||||||
@ -19,6 +19,7 @@ ENTITY_ID_FORMAT = DOMAIN + '.{}'
|
|||||||
|
|
||||||
# Maps discovered services to their platforms
|
# Maps discovered services to their platforms
|
||||||
DISCOVERY_PLATFORMS = {
|
DISCOVERY_PLATFORMS = {
|
||||||
|
bloomsky.DISCOVER_SENSORS: 'bloomsky',
|
||||||
wink.DISCOVER_SENSORS: 'wink',
|
wink.DISCOVER_SENSORS: 'wink',
|
||||||
zwave.DISCOVER_SENSORS: 'zwave',
|
zwave.DISCOVER_SENSORS: 'zwave',
|
||||||
isy994.DISCOVER_SENSORS: 'isy994',
|
isy994.DISCOVER_SENSORS: 'isy994',
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
"""
|
"""
|
||||||
homeassistant.components.sensor.bloomsky
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
Support the sensor of a BloomSky weather station.
|
Support the sensor of a BloomSky weather station.
|
||||||
|
|
||||||
For more details about this component, please refer to the documentation at
|
For more details about this component, please refer to the documentation at
|
||||||
@ -8,6 +6,7 @@ https://home-assistant.io/components/sensor.bloomsky/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from homeassistant.const import TEMP_FAHRENHEIT
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.loader import get_component
|
from homeassistant.loader import get_component
|
||||||
|
|
||||||
@ -16,14 +15,12 @@ DEPENDENCIES = ["bloomsky"]
|
|||||||
# These are the available sensors
|
# These are the available sensors
|
||||||
SENSOR_TYPES = ["Temperature",
|
SENSOR_TYPES = ["Temperature",
|
||||||
"Humidity",
|
"Humidity",
|
||||||
"Rain",
|
|
||||||
"Pressure",
|
"Pressure",
|
||||||
"Luminance",
|
"Luminance",
|
||||||
"Night",
|
|
||||||
"UVIndex"]
|
"UVIndex"]
|
||||||
|
|
||||||
# Sensor units - these do not currently align with the API documentation
|
# Sensor units - these do not currently align with the API documentation
|
||||||
SENSOR_UNITS = {"Temperature": "°F",
|
SENSOR_UNITS = {"Temperature": TEMP_FAHRENHEIT,
|
||||||
"Humidity": "%",
|
"Humidity": "%",
|
||||||
"Pressure": "inHg",
|
"Pressure": "inHg",
|
||||||
"Luminance": "cd/m²"}
|
"Luminance": "cd/m²"}
|
||||||
@ -35,13 +32,12 @@ FORMAT_NUMBERS = ["Temperature", "Pressure"]
|
|||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up the available BloomSky weather sensors."""
|
"""Set up the available BloomSky weather sensors."""
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
bloomsky = get_component('bloomsky')
|
bloomsky = get_component('bloomsky')
|
||||||
|
sensors = config.get('monitored_conditions', SENSOR_TYPES)
|
||||||
|
|
||||||
for device_key in bloomsky.BLOOMSKY.devices:
|
for device in bloomsky.BLOOMSKY.devices.values():
|
||||||
device = bloomsky.BLOOMSKY.devices[device_key]
|
for variable in sensors:
|
||||||
for variable in config["monitored_conditions"]:
|
|
||||||
if variable in SENSOR_TYPES:
|
if variable in SENSOR_TYPES:
|
||||||
add_devices([BloomSkySensor(bloomsky.BLOOMSKY,
|
add_devices([BloomSkySensor(bloomsky.BLOOMSKY,
|
||||||
device,
|
device,
|
||||||
@ -54,17 +50,23 @@ class BloomSkySensor(Entity):
|
|||||||
"""Represents a single sensor in a BloomSky device."""
|
"""Represents a single sensor in a BloomSky device."""
|
||||||
|
|
||||||
def __init__(self, bs, device, sensor_name):
|
def __init__(self, bs, device, sensor_name):
|
||||||
|
"""Initialize a bloomsky sensor."""
|
||||||
self._bloomsky = bs
|
self._bloomsky = bs
|
||||||
self._device_id = device["DeviceID"]
|
self._device_id = device["DeviceID"]
|
||||||
self._client_name = device["DeviceName"]
|
|
||||||
self._sensor_name = sensor_name
|
self._sensor_name = sensor_name
|
||||||
self._state = self.process_state(device)
|
self._name = "{} {}".format(device["DeviceName"], sensor_name)
|
||||||
self._sensor_update = ""
|
self._unique_id = "bloomsky_sensor {}".format(self._name)
|
||||||
|
self.update()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""The name of the BloomSky device and this sensor."""
|
"""The name of the BloomSky device and this sensor."""
|
||||||
return "{} {}".format(self._client_name, self._sensor_name)
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unique_id(self):
|
||||||
|
"""Unique ID for this sensor."""
|
||||||
|
return self._unique_id
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
@ -73,34 +75,17 @@ class BloomSkySensor(Entity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
""" This sensor's units. """
|
"""Return the sensor units."""
|
||||||
return SENSOR_UNITS.get(self._sensor_name, None)
|
return SENSOR_UNITS.get(self._sensor_name, None)
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Request an update from the BloomSky API."""
|
"""Request an update from the BloomSky API."""
|
||||||
self._bloomsky.refresh_devices()
|
self._bloomsky.refresh_devices()
|
||||||
# TS is a Unix epoch timestamp for the last time the BloomSky servers
|
|
||||||
# heard from this device. If that value hasn't changed, the value has
|
|
||||||
# not been updated.
|
|
||||||
last_ts = self._bloomsky.devices[self._device_id]["Data"]["TS"]
|
|
||||||
if last_ts != self._sensor_update:
|
|
||||||
self.process_state(self._bloomsky.devices[self._device_id])
|
|
||||||
self._sensor_update = last_ts
|
|
||||||
|
|
||||||
def process_state(self, device):
|
state = \
|
||||||
""" Handle the response from the BloomSky API for this sensor. """
|
self._bloomsky.devices[self._device_id]["Data"][self._sensor_name]
|
||||||
data = device["Data"][self._sensor_name]
|
|
||||||
if self._sensor_name == "Rain":
|
if self._sensor_name in FORMAT_NUMBERS:
|
||||||
if data:
|
self._state = "{0:.2f}".format(state)
|
||||||
self._state = "Raining"
|
|
||||||
else:
|
else:
|
||||||
self._state = "Not raining"
|
self._state = state
|
||||||
elif self._sensor_name == "Night":
|
|
||||||
if data:
|
|
||||||
self._state = "Nighttime"
|
|
||||||
else:
|
|
||||||
self._state = "Daytime"
|
|
||||||
elif self._sensor_name in FORMAT_NUMBERS:
|
|
||||||
self._state = "{0:.2f}".format(data)
|
|
||||||
else:
|
|
||||||
self._state = data
|
|
||||||
|
@ -146,7 +146,7 @@ class MockModule(object):
|
|||||||
self.DEPENDENCIES = dependencies
|
self.DEPENDENCIES = dependencies
|
||||||
# Setup a mock setup if none given.
|
# Setup a mock setup if none given.
|
||||||
if setup is None:
|
if setup is None:
|
||||||
self.setup = lambda hass, config: False
|
self.setup = lambda hass, config: True
|
||||||
else:
|
else:
|
||||||
self.setup = setup
|
self.setup = setup
|
||||||
|
|
||||||
|
@ -31,8 +31,7 @@ class TestBinarySensor(unittest.TestCase):
|
|||||||
def test_attributes(self):
|
def test_attributes(self):
|
||||||
"""Test binary sensor attributes."""
|
"""Test binary sensor attributes."""
|
||||||
sensor = binary_sensor.BinarySensorDevice()
|
sensor = binary_sensor.BinarySensorDevice()
|
||||||
self.assertEqual({'sensor_class': None},
|
self.assertEqual({}, sensor.state_attributes)
|
||||||
sensor.state_attributes)
|
|
||||||
with mock.patch('homeassistant.components.binary_sensor.'
|
with mock.patch('homeassistant.components.binary_sensor.'
|
||||||
'BinarySensorDevice.sensor_class',
|
'BinarySensorDevice.sensor_class',
|
||||||
new='motion'):
|
new='motion'):
|
||||||
|
@ -9,13 +9,13 @@ import os
|
|||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from homeassistant import bootstrap
|
from homeassistant import bootstrap, loader
|
||||||
from homeassistant.const import (__version__, CONF_LATITUDE, CONF_LONGITUDE,
|
from homeassistant.const import (__version__, CONF_LATITUDE, CONF_LONGITUDE,
|
||||||
CONF_NAME, CONF_CUSTOMIZE)
|
CONF_NAME, CONF_CUSTOMIZE)
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
from tests.common import get_test_home_assistant
|
from tests.common import get_test_home_assistant, MockModule
|
||||||
|
|
||||||
|
|
||||||
class TestBootstrap(unittest.TestCase):
|
class TestBootstrap(unittest.TestCase):
|
||||||
@ -61,6 +61,7 @@ class TestBootstrap(unittest.TestCase):
|
|||||||
self.assertTrue(os.path.isfile(check_file))
|
self.assertTrue(os.path.isfile(check_file))
|
||||||
bootstrap.process_ha_config_upgrade(hass)
|
bootstrap.process_ha_config_upgrade(hass)
|
||||||
self.assertFalse(os.path.isfile(check_file))
|
self.assertFalse(os.path.isfile(check_file))
|
||||||
|
hass.stop()
|
||||||
|
|
||||||
def test_not_remove_lib_if_not_upgrade(self):
|
def test_not_remove_lib_if_not_upgrade(self):
|
||||||
with tempfile.TemporaryDirectory() as config_dir:
|
with tempfile.TemporaryDirectory() as config_dir:
|
||||||
@ -82,6 +83,7 @@ class TestBootstrap(unittest.TestCase):
|
|||||||
bootstrap.process_ha_config_upgrade(hass)
|
bootstrap.process_ha_config_upgrade(hass)
|
||||||
|
|
||||||
self.assertTrue(os.path.isfile(check_file))
|
self.assertTrue(os.path.isfile(check_file))
|
||||||
|
hass.stop()
|
||||||
|
|
||||||
def test_entity_customization(self):
|
def test_entity_customization(self):
|
||||||
""" Test entity customization through config """
|
""" Test entity customization through config """
|
||||||
@ -102,3 +104,19 @@ class TestBootstrap(unittest.TestCase):
|
|||||||
state = hass.states.get('test.test')
|
state = hass.states.get('test.test')
|
||||||
|
|
||||||
self.assertTrue(state.attributes['hidden'])
|
self.assertTrue(state.attributes['hidden'])
|
||||||
|
hass.stop()
|
||||||
|
|
||||||
|
def test_handle_setup_circular_dependency(self):
|
||||||
|
hass = get_test_home_assistant()
|
||||||
|
|
||||||
|
loader.set_component('comp_b', MockModule('comp_b', ['comp_a']))
|
||||||
|
|
||||||
|
def setup_a(hass, config):
|
||||||
|
bootstrap.setup_component(hass, 'comp_b')
|
||||||
|
return True
|
||||||
|
|
||||||
|
loader.set_component('comp_a', MockModule('comp_a', setup=setup_a))
|
||||||
|
|
||||||
|
bootstrap.setup_component(hass, 'comp_a')
|
||||||
|
self.assertEqual(['comp_a'], hass.config.components)
|
||||||
|
hass.stop()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user