mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 10:47:10 +00:00
Fix PEP257 issues
This commit is contained in:
parent
986c9c55bf
commit
f22a40c3e8
@ -44,6 +44,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
# pylint: disable=too-many-arguments
|
# pylint: disable=too-many-arguments
|
||||||
class CommandBinarySensor(BinarySensorDevice):
|
class CommandBinarySensor(BinarySensorDevice):
|
||||||
"""Represent a command line binary sensor."""
|
"""Represent a command line binary sensor."""
|
||||||
|
|
||||||
def __init__(self, hass, data, name, payload_on,
|
def __init__(self, hass, data, name, payload_on,
|
||||||
payload_off, value_template):
|
payload_off, value_template):
|
||||||
"""Initialize the Command line binary sensor."""
|
"""Initialize the Command line binary sensor."""
|
||||||
|
@ -33,7 +33,6 @@ DEVICE_MAPPINGS = {
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the Z-Wave platform for sensors."""
|
"""Setup the Z-Wave platform for sensors."""
|
||||||
|
|
||||||
if discovery_info is None or NETWORK is None:
|
if discovery_info is None or NETWORK is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -63,9 +62,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
|
|
||||||
|
|
||||||
class ZWaveBinarySensor(BinarySensorDevice, ZWaveDeviceEntity):
|
class ZWaveBinarySensor(BinarySensorDevice, ZWaveDeviceEntity):
|
||||||
"""Represents a binary sensor within Z-Wave."""
|
"""Representation of a binary sensor within Z-Wave."""
|
||||||
|
|
||||||
def __init__(self, value, sensor_class):
|
def __init__(self, value, sensor_class):
|
||||||
|
"""Initialize the sensor."""
|
||||||
self._sensor_type = sensor_class
|
self._sensor_type = sensor_class
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
from openzwave.network import ZWaveNetwork
|
from openzwave.network import ZWaveNetwork
|
||||||
@ -98,12 +98,10 @@ class ZWaveBinarySensor(BinarySensorDevice, ZWaveDeviceEntity):
|
|||||||
|
|
||||||
|
|
||||||
class ZWaveTriggerSensor(ZWaveBinarySensor):
|
class ZWaveTriggerSensor(ZWaveBinarySensor):
|
||||||
"""
|
"""Representation of a stateless sensor within Z-Wave."""
|
||||||
Represents a stateless sensor which triggers events just 'On'
|
|
||||||
within Z-Wave.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, sensor_value, sensor_class, hass, re_arm_sec=60):
|
def __init__(self, sensor_value, sensor_class, hass, re_arm_sec=60):
|
||||||
|
"""Initialize the sensor."""
|
||||||
super(ZWaveTriggerSensor, self).__init__(sensor_value, sensor_class)
|
super(ZWaveTriggerSensor, self).__init__(sensor_value, sensor_class)
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
self.re_arm_sec = re_arm_sec
|
self.re_arm_sec = re_arm_sec
|
||||||
|
@ -1,9 +1,4 @@
|
|||||||
"""
|
"""Handle the frontend for Home Assistant."""
|
||||||
homeassistant.components.frontend
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
Provides a frontend for Home Assistant.
|
|
||||||
"""
|
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
@ -58,7 +53,7 @@ def setup(hass, config):
|
|||||||
|
|
||||||
|
|
||||||
def _handle_get_api_bootstrap(handler, path_match, data):
|
def _handle_get_api_bootstrap(handler, path_match, data):
|
||||||
""" Returns all data needed to bootstrap Home Assistant. """
|
"""Return all data needed to bootstrap Home Assistant."""
|
||||||
hass = handler.server.hass
|
hass = handler.server.hass
|
||||||
|
|
||||||
handler.write_json({
|
handler.write_json({
|
||||||
@ -70,7 +65,7 @@ def _handle_get_api_bootstrap(handler, path_match, data):
|
|||||||
|
|
||||||
|
|
||||||
def _handle_get_root(handler, path_match, data):
|
def _handle_get_root(handler, path_match, data):
|
||||||
""" Renders the frontend. """
|
"""Render the frontend."""
|
||||||
handler.send_response(HTTP_OK)
|
handler.send_response(HTTP_OK)
|
||||||
handler.send_header('Content-type', 'text/html; charset=utf-8')
|
handler.send_header('Content-type', 'text/html; charset=utf-8')
|
||||||
handler.end_headers()
|
handler.end_headers()
|
||||||
@ -95,7 +90,7 @@ def _handle_get_root(handler, path_match, data):
|
|||||||
|
|
||||||
|
|
||||||
def _handle_get_service_worker(handler, path_match, data):
|
def _handle_get_service_worker(handler, path_match, data):
|
||||||
""" Returns service worker for the frontend. """
|
"""Return service worker for the frontend."""
|
||||||
if handler.server.development:
|
if handler.server.development:
|
||||||
sw_path = "home-assistant-polymer/build/service_worker.js"
|
sw_path = "home-assistant-polymer/build/service_worker.js"
|
||||||
else:
|
else:
|
||||||
@ -106,7 +101,7 @@ def _handle_get_service_worker(handler, path_match, data):
|
|||||||
|
|
||||||
|
|
||||||
def _handle_get_static(handler, path_match, data):
|
def _handle_get_static(handler, path_match, data):
|
||||||
""" Returns a static file for the frontend. """
|
"""Return a static file for the frontend."""
|
||||||
req_file = util.sanitize_path(path_match.group('file'))
|
req_file = util.sanitize_path(path_match.group('file'))
|
||||||
|
|
||||||
# Strip md5 hash out
|
# Strip md5 hash out
|
||||||
@ -120,9 +115,7 @@ def _handle_get_static(handler, path_match, data):
|
|||||||
|
|
||||||
|
|
||||||
def _handle_get_local(handler, path_match, data):
|
def _handle_get_local(handler, path_match, data):
|
||||||
"""
|
"""Return a static file from the hass.config.path/www for the frontend."""
|
||||||
Returns a static file from the hass.config.path/www for the frontend.
|
|
||||||
"""
|
|
||||||
req_file = util.sanitize_path(path_match.group('file'))
|
req_file = util.sanitize_path(path_match.group('file'))
|
||||||
|
|
||||||
path = handler.server.hass.config.path('www', req_file)
|
path = handler.server.hass.config.path('www', req_file)
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
""" DO NOT MODIFY. Auto-generated by update_mdi script """
|
"""DO NOT MODIFY. Auto-generated by update_mdi script."""
|
||||||
VERSION = "2f4adc5d3ad6d2f73bf69ed29b7594fd"
|
VERSION = "2f4adc5d3ad6d2f73bf69ed29b7594fd"
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
""" DO NOT MODIFY. Auto-generated by build_frontend script """
|
"""DO NOT MODIFY. Auto-generated by build_frontend script."""
|
||||||
VERSION = "625d9bc6f119ee8f815b30104b70cb43"
|
VERSION = "625d9bc6f119ee8f815b30104b70cb43"
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
"""
|
"""
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
Support for Powerview scenes from a Powerview hub.
|
||||||
Gets powerview scenes from a powerview hub
|
|
||||||
defined by a Hunter Douglas powerview app.
|
|
||||||
|
|
||||||
For more details about this component, please refer to the documentation at
|
For more details about this component, please refer to the documentation at
|
||||||
https://home-assistant.io/components/scene/
|
https://home-assistant.io/components/scene/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.scene import Scene
|
from homeassistant.components.scene import Scene
|
||||||
@ -21,7 +18,7 @@ HUB_ADDRESS = 'address'
|
|||||||
|
|
||||||
# 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):
|
||||||
"""sets up the powerview scenes stored in a powerview hub"""
|
"""Setup the powerview scenes stored in a Powerview hub."""
|
||||||
import powerview
|
import powerview
|
||||||
|
|
||||||
hub_address = config.get(HUB_ADDRESS)
|
hub_address = config.get(HUB_ADDRESS)
|
||||||
@ -41,15 +38,17 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
|
|
||||||
|
|
||||||
class PowerViewScene(Scene):
|
class PowerViewScene(Scene):
|
||||||
""" A scene is a group of entities and the states we want them to be. """
|
"""Representation of a Powerview scene."""
|
||||||
|
|
||||||
def __init__(self, hass, scene_data, room_data, pv_instance):
|
def __init__(self, hass, scene_data, room_data, pv_instance):
|
||||||
|
"""Initialize the scene."""
|
||||||
self.pv_instance = pv_instance
|
self.pv_instance = pv_instance
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
self.scene_data = scene_data
|
self.scene_data = scene_data
|
||||||
self._sync_room_data(room_data)
|
self._sync_room_data(room_data)
|
||||||
|
|
||||||
def _sync_room_data(self, room_data):
|
def _sync_room_data(self, room_data):
|
||||||
|
"""Sync the room data."""
|
||||||
room = next((room for room in room_data["roomData"]
|
room = next((room for room in room_data["roomData"]
|
||||||
if room["id"] == self.scene_data["roomId"]), None)
|
if room["id"] == self.scene_data["roomId"]), None)
|
||||||
if room is not None:
|
if room is not None:
|
||||||
@ -57,12 +56,14 @@ class PowerViewScene(Scene):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
"""Return the name of the scene."""
|
||||||
return self.scene_data["name"]
|
return self.scene_data["name"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
|
"""Return the state attributes."""
|
||||||
return {"roomName": self.scene_data["roomName"]}
|
return {"roomName": self.scene_data["roomName"]}
|
||||||
|
|
||||||
def activate(self):
|
def activate(self):
|
||||||
""" Activates scene. Tries to get entities into requested state. """
|
"""Activate the scene. Tries to get entities into requested state."""
|
||||||
self.pv_instance.activate_scene(self.scene_data["id"])
|
self.pv_instance.activate_scene(self.scene_data["id"])
|
||||||
|
@ -256,6 +256,7 @@ def forgiving_float(value):
|
|||||||
|
|
||||||
class TemplateEnvironment(ImmutableSandboxedEnvironment):
|
class TemplateEnvironment(ImmutableSandboxedEnvironment):
|
||||||
"""The Home Assistant template environment."""
|
"""The Home Assistant template environment."""
|
||||||
|
|
||||||
def is_safe_callable(self, obj):
|
def is_safe_callable(self, obj):
|
||||||
"""Test if callback is safe."""
|
"""Test if callback is safe."""
|
||||||
return isinstance(obj, AllStates) or super().is_safe_callable(obj)
|
return isinstance(obj, AllStates) or super().is_safe_callable(obj)
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
"""
|
"""Generate an updated requirements_all.txt."""
|
||||||
Generate an updated requirements_all.txt
|
|
||||||
"""
|
|
||||||
|
|
||||||
import importlib
|
import importlib
|
||||||
import os
|
import os
|
||||||
import pkgutil
|
import pkgutil
|
||||||
@ -95,19 +92,19 @@ def gather_modules():
|
|||||||
|
|
||||||
|
|
||||||
def write_file(data):
|
def write_file(data):
|
||||||
""" Writes the modules to the requirements_all.txt. """
|
"""Write the modules to the requirements_all.txt."""
|
||||||
with open('requirements_all.txt', 'w+') as req_file:
|
with open('requirements_all.txt', 'w+') as req_file:
|
||||||
req_file.write(data)
|
req_file.write(data)
|
||||||
|
|
||||||
|
|
||||||
def validate_file(data):
|
def validate_file(data):
|
||||||
""" Validates if requirements_all.txt is up to date. """
|
"""Validate if requirements_all.txt is up to date."""
|
||||||
with open('requirements_all.txt', 'r') as req_file:
|
with open('requirements_all.txt', 'r') as req_file:
|
||||||
return data == ''.join(req_file)
|
return data == ''.join(req_file)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
""" Main """
|
"""Main section of the script."""
|
||||||
if not os.path.isfile('requirements_all.txt'):
|
if not os.path.isfile('requirements_all.txt'):
|
||||||
print('Run this from HA root dir')
|
print('Run this from HA root dir')
|
||||||
return
|
return
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
#! /usr/bin/python
|
#! /usr/bin/python
|
||||||
"""
|
"""
|
||||||
Query the Home Assistant API for available entities then print them and any
|
Query the Home Assistant API for available entities.
|
||||||
desired attributes to the screen.
|
|
||||||
|
Output is printed to stdout.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
@ -17,19 +18,19 @@ import json
|
|||||||
|
|
||||||
|
|
||||||
def main(password, askpass, attrs, address, port):
|
def main(password, askpass, attrs, address, port):
|
||||||
""" fetch Home Assistant api json page and post process """
|
"""Fetch Home Assistant API JSON page and post process."""
|
||||||
# ask for password
|
# Ask for password
|
||||||
if askpass:
|
if askpass:
|
||||||
password = getpass.getpass('Home Assistant API Password: ')
|
password = getpass.getpass('Home Assistant API Password: ')
|
||||||
|
|
||||||
# fetch API result
|
# Fetch API result
|
||||||
url = mk_url(address, port, password)
|
url = mk_url(address, port, password)
|
||||||
response = urlopen(url).read()
|
response = urlopen(url).read()
|
||||||
if PYTHON == 3:
|
if PYTHON == 3:
|
||||||
response = response.decode('utf-8')
|
response = response.decode('utf-8')
|
||||||
data = json.loads(response)
|
data = json.loads(response)
|
||||||
|
|
||||||
# parse data
|
# Parse data
|
||||||
output = {'entity_id': []}
|
output = {'entity_id': []}
|
||||||
output.update([(attr, []) for attr in attrs])
|
output.update([(attr, []) for attr in attrs])
|
||||||
for item in data:
|
for item in data:
|
||||||
@ -37,18 +38,18 @@ def main(password, askpass, attrs, address, port):
|
|||||||
for attr in attrs:
|
for attr in attrs:
|
||||||
output[attr].append(item['attributes'].get(attr, ''))
|
output[attr].append(item['attributes'].get(attr, ''))
|
||||||
|
|
||||||
# output data
|
# Output data
|
||||||
print_table(output, ['entity_id'] + attrs)
|
print_table(output, ['entity_id'] + attrs)
|
||||||
|
|
||||||
|
|
||||||
def print_table(data, columns):
|
def print_table(data, columns):
|
||||||
""" format and print a table of data from a dictionary """
|
"""Format and print a table of data from a dictionary."""
|
||||||
# get column lengths
|
# Get column lengths
|
||||||
lengths = {}
|
lengths = {}
|
||||||
for key, value in data.items():
|
for key, value in data.items():
|
||||||
lengths[key] = max([len(str(val)) for val in value] + [len(key)])
|
lengths[key] = max([len(str(val)) for val in value] + [len(key)])
|
||||||
|
|
||||||
# print header
|
# Print header
|
||||||
for item in columns:
|
for item in columns:
|
||||||
itemup = item.upper()
|
itemup = item.upper()
|
||||||
sys.stdout.write(itemup + ' ' * (lengths[item] - len(item) + 4))
|
sys.stdout.write(itemup + ' ' * (lengths[item] - len(item) + 4))
|
||||||
@ -63,7 +64,7 @@ def print_table(data, columns):
|
|||||||
|
|
||||||
|
|
||||||
def mk_url(address, port, password):
|
def mk_url(address, port, password):
|
||||||
""" construct the url call for the api states page """
|
"""Construct the URL call for the API states page."""
|
||||||
url = ''
|
url = ''
|
||||||
if address.startswith('http://'):
|
if address.startswith('http://'):
|
||||||
url += address
|
url += address
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
"""
|
"""Download the latest Polymer v1 iconset for materialdesignicons.com."""
|
||||||
Downloads the latest Polymer v1 iconset version for materialdesignicons.com
|
|
||||||
"""
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@ -21,7 +19,7 @@ ICONSET_OUTPUT = os.path.join(OUTPUT_BASE, 'www_static', 'mdi.html')
|
|||||||
|
|
||||||
|
|
||||||
def get_local_version():
|
def get_local_version():
|
||||||
""" Parse local version. """
|
"""Parse the local version."""
|
||||||
try:
|
try:
|
||||||
with open(VERSION_OUTPUT) as inp:
|
with open(VERSION_OUTPUT) as inp:
|
||||||
for line in inp:
|
for line in inp:
|
||||||
@ -68,6 +66,7 @@ def write_component(version, source):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
"""Main section of the script."""
|
||||||
# All scripts should have their current work dir set to project root
|
# All scripts should have their current work dir set to project root
|
||||||
if os.path.basename(os.getcwd()) == 'script':
|
if os.path.basename(os.getcwd()) == 'script':
|
||||||
os.chdir('..')
|
os.chdir('..')
|
||||||
|
@ -102,6 +102,7 @@ def ensure_sun_set(hass):
|
|||||||
|
|
||||||
|
|
||||||
def mock_state_change_event(hass, new_state, old_state=None):
|
def mock_state_change_event(hass, new_state, old_state=None):
|
||||||
|
"""Mock state change envent."""
|
||||||
event_data = {
|
event_data = {
|
||||||
'entity_id': new_state.entity_id,
|
'entity_id': new_state.entity_id,
|
||||||
'new_state': new_state,
|
'new_state': new_state,
|
||||||
@ -133,14 +134,17 @@ def mock_mqtt_component(hass, mock_mqtt):
|
|||||||
|
|
||||||
class MockHTTP(object):
|
class MockHTTP(object):
|
||||||
"""Mock the HTTP module."""
|
"""Mock the HTTP module."""
|
||||||
|
|
||||||
def register_path(self, method, url, callback, require_auth=True):
|
def register_path(self, method, url, callback, require_auth=True):
|
||||||
|
"""Register a path."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class MockModule(object):
|
class MockModule(object):
|
||||||
""" Provides a fake module. """
|
"""Representation of a fake module."""
|
||||||
|
|
||||||
def __init__(self, domain=None, dependencies=[], setup=None):
|
def __init__(self, domain=None, dependencies=[], setup=None):
|
||||||
|
"""Initialize the mock module."""
|
||||||
self.DOMAIN = domain
|
self.DOMAIN = domain
|
||||||
self.DEPENDENCIES = dependencies
|
self.DEPENDENCIES = dependencies
|
||||||
# Setup a mock setup if none given.
|
# Setup a mock setup if none given.
|
||||||
@ -166,7 +170,9 @@ class MockPlatform(object):
|
|||||||
|
|
||||||
class MockToggleDevice(ToggleEntity):
|
class MockToggleDevice(ToggleEntity):
|
||||||
"""Provide a mock toggle device."""
|
"""Provide a mock toggle device."""
|
||||||
|
|
||||||
def __init__(self, name, state):
|
def __init__(self, name, state):
|
||||||
|
"""Initialize the mock device."""
|
||||||
self._name = name or DEVICE_DEFAULT_NAME
|
self._name = name or DEVICE_DEFAULT_NAME
|
||||||
self._state = state
|
self._state = state
|
||||||
self.calls = []
|
self.calls = []
|
||||||
@ -179,7 +185,7 @@ class MockToggleDevice(ToggleEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Returns the name of the device if any."""
|
"""Return the name of the device if any."""
|
||||||
self.calls.append(('state', {}))
|
self.calls.append(('state', {}))
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
|
|
||||||
def get_scanner(hass, config):
|
def get_scanner(hass, config):
|
||||||
"""Returns a mock scanner."""
|
"""Return a mock scanner."""
|
||||||
return SCANNER
|
return SCANNER
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
"""The tests for the helpers."""
|
@ -12,7 +12,7 @@ class TestHelpersEntity(unittest.TestCase):
|
|||||||
"""Test homeassistant.helpers.entity module."""
|
"""Test homeassistant.helpers.entity module."""
|
||||||
|
|
||||||
def setUp(self): # pylint: disable=invalid-name
|
def setUp(self): # pylint: disable=invalid-name
|
||||||
"""Init needed objects."""
|
"""Setup things to be run when tests are started."""
|
||||||
self.entity = entity.Entity()
|
self.entity = entity.Entity()
|
||||||
self.entity.entity_id = 'test.overwrite_hidden_true'
|
self.entity.entity_id = 'test.overwrite_hidden_true'
|
||||||
self.hass = self.entity.hass = get_test_home_assistant()
|
self.hass = self.entity.hass = get_test_home_assistant()
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
"""Test the entity component helper."""
|
"""The tests for the Entity component helper."""
|
||||||
# pylint: disable=protected-access,too-many-public-methods
|
# pylint: disable=protected-access,too-many-public-methods
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
import logging
|
import logging
|
||||||
@ -20,7 +20,10 @@ DOMAIN = "test_domain"
|
|||||||
|
|
||||||
|
|
||||||
class EntityTest(Entity):
|
class EntityTest(Entity):
|
||||||
|
"""Test for the Entity component."""
|
||||||
|
|
||||||
def __init__(self, **values):
|
def __init__(self, **values):
|
||||||
|
"""Initialize an entity."""
|
||||||
self._values = values
|
self._values = values
|
||||||
|
|
||||||
if 'entity_id' in values:
|
if 'entity_id' in values:
|
||||||
@ -28,24 +31,28 @@ class EntityTest(Entity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
"""Return the name of the entity."""
|
||||||
return self._handle('name')
|
return self._handle('name')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self):
|
||||||
|
"""Return the ste of the polling."""
|
||||||
return self._handle('should_poll')
|
return self._handle('should_poll')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
|
"""Return the unique ID of the entity."""
|
||||||
return self._handle('unique_id')
|
return self._handle('unique_id')
|
||||||
|
|
||||||
def _handle(self, attr):
|
def _handle(self, attr):
|
||||||
|
"""Helper for the attributes."""
|
||||||
if attr in self._values:
|
if attr in self._values:
|
||||||
return self._values[attr]
|
return self._values[attr]
|
||||||
return getattr(super(), attr)
|
return getattr(super(), attr)
|
||||||
|
|
||||||
|
|
||||||
class TestHelpersEntityComponent(unittest.TestCase):
|
class TestHelpersEntityComponent(unittest.TestCase):
|
||||||
""" Tests homeassistant.helpers.entity_component module. """
|
"""Test homeassistant.helpers.entity_component module."""
|
||||||
|
|
||||||
def setUp(self): # pylint: disable=invalid-name
|
def setUp(self): # pylint: disable=invalid-name
|
||||||
"""Initialize a test Home Assistant instance."""
|
"""Initialize a test Home Assistant instance."""
|
||||||
@ -56,6 +63,7 @@ class TestHelpersEntityComponent(unittest.TestCase):
|
|||||||
self.hass.stop()
|
self.hass.stop()
|
||||||
|
|
||||||
def test_setting_up_group(self):
|
def test_setting_up_group(self):
|
||||||
|
"""Setup the setting of a group."""
|
||||||
component = EntityComponent(_LOGGER, DOMAIN, self.hass,
|
component = EntityComponent(_LOGGER, DOMAIN, self.hass,
|
||||||
group_name='everyone')
|
group_name='everyone')
|
||||||
|
|
||||||
@ -82,6 +90,7 @@ class TestHelpersEntityComponent(unittest.TestCase):
|
|||||||
sorted(group.attributes.get('entity_id'))
|
sorted(group.attributes.get('entity_id'))
|
||||||
|
|
||||||
def test_polling_only_updates_entities_it_should_poll(self):
|
def test_polling_only_updates_entities_it_should_poll(self):
|
||||||
|
"""Test the polling of only updated entities."""
|
||||||
component = EntityComponent(_LOGGER, DOMAIN, self.hass, 20)
|
component = EntityComponent(_LOGGER, DOMAIN, self.hass, 20)
|
||||||
|
|
||||||
no_poll_ent = EntityTest(should_poll=False)
|
no_poll_ent = EntityTest(should_poll=False)
|
||||||
@ -117,6 +126,7 @@ class TestHelpersEntityComponent(unittest.TestCase):
|
|||||||
assert 2 == len(self.hass.states.entity_ids())
|
assert 2 == len(self.hass.states.entity_ids())
|
||||||
|
|
||||||
def test_not_adding_duplicate_entities(self):
|
def test_not_adding_duplicate_entities(self):
|
||||||
|
"""Test for not adding duplicate entities."""
|
||||||
component = EntityComponent(_LOGGER, DOMAIN, self.hass)
|
component = EntityComponent(_LOGGER, DOMAIN, self.hass)
|
||||||
|
|
||||||
assert 0 == len(self.hass.states.entity_ids())
|
assert 0 == len(self.hass.states.entity_ids())
|
||||||
@ -130,6 +140,7 @@ class TestHelpersEntityComponent(unittest.TestCase):
|
|||||||
assert 1 == len(self.hass.states.entity_ids())
|
assert 1 == len(self.hass.states.entity_ids())
|
||||||
|
|
||||||
def test_not_assigning_entity_id_if_prescribes_one(self):
|
def test_not_assigning_entity_id_if_prescribes_one(self):
|
||||||
|
"""Test for not assigning an entity ID."""
|
||||||
component = EntityComponent(_LOGGER, DOMAIN, self.hass)
|
component = EntityComponent(_LOGGER, DOMAIN, self.hass)
|
||||||
|
|
||||||
assert 'hello.world' not in self.hass.states.entity_ids()
|
assert 'hello.world' not in self.hass.states.entity_ids()
|
||||||
@ -139,6 +150,7 @@ class TestHelpersEntityComponent(unittest.TestCase):
|
|||||||
assert 'hello.world' in self.hass.states.entity_ids()
|
assert 'hello.world' in self.hass.states.entity_ids()
|
||||||
|
|
||||||
def test_extract_from_service_returns_all_if_no_entity_id(self):
|
def test_extract_from_service_returns_all_if_no_entity_id(self):
|
||||||
|
"""Test the extraction of everything from service."""
|
||||||
component = EntityComponent(_LOGGER, DOMAIN, self.hass)
|
component = EntityComponent(_LOGGER, DOMAIN, self.hass)
|
||||||
component.add_entities([
|
component.add_entities([
|
||||||
EntityTest(name='test_1'),
|
EntityTest(name='test_1'),
|
||||||
@ -152,6 +164,7 @@ class TestHelpersEntityComponent(unittest.TestCase):
|
|||||||
component.extract_from_service(call))
|
component.extract_from_service(call))
|
||||||
|
|
||||||
def test_extract_from_service_filter_out_non_existing_entities(self):
|
def test_extract_from_service_filter_out_non_existing_entities(self):
|
||||||
|
"""Test the extraction of non existing entities from service."""
|
||||||
component = EntityComponent(_LOGGER, DOMAIN, self.hass)
|
component = EntityComponent(_LOGGER, DOMAIN, self.hass)
|
||||||
component.add_entities([
|
component.add_entities([
|
||||||
EntityTest(name='test_1'),
|
EntityTest(name='test_1'),
|
||||||
@ -166,6 +179,7 @@ class TestHelpersEntityComponent(unittest.TestCase):
|
|||||||
[ent.entity_id for ent in component.extract_from_service(call)]
|
[ent.entity_id for ent in component.extract_from_service(call)]
|
||||||
|
|
||||||
def test_setup_loads_platforms(self):
|
def test_setup_loads_platforms(self):
|
||||||
|
"""Test the loading of the platforms."""
|
||||||
component_setup = Mock(return_value=True)
|
component_setup = Mock(return_value=True)
|
||||||
platform_setup = Mock(return_value=None)
|
platform_setup = Mock(return_value=None)
|
||||||
loader.set_component(
|
loader.set_component(
|
||||||
@ -189,6 +203,7 @@ class TestHelpersEntityComponent(unittest.TestCase):
|
|||||||
assert platform_setup.called
|
assert platform_setup.called
|
||||||
|
|
||||||
def test_setup_recovers_when_setup_raises(self):
|
def test_setup_recovers_when_setup_raises(self):
|
||||||
|
"""Test the setup if exceptions are happening."""
|
||||||
platform1_setup = Mock(side_effect=Exception('Broken'))
|
platform1_setup = Mock(side_effect=Exception('Broken'))
|
||||||
platform2_setup = Mock(return_value=None)
|
platform2_setup = Mock(return_value=None)
|
||||||
|
|
||||||
@ -212,6 +227,7 @@ class TestHelpersEntityComponent(unittest.TestCase):
|
|||||||
@patch('homeassistant.helpers.entity_component.EntityComponent'
|
@patch('homeassistant.helpers.entity_component.EntityComponent'
|
||||||
'._setup_platform')
|
'._setup_platform')
|
||||||
def test_setup_does_discovery(self, mock_setup):
|
def test_setup_does_discovery(self, mock_setup):
|
||||||
|
"""Test setup for discovery."""
|
||||||
component = EntityComponent(
|
component = EntityComponent(
|
||||||
_LOGGER, DOMAIN, self.hass, discovery_platforms={
|
_LOGGER, DOMAIN, self.hass, discovery_platforms={
|
||||||
'discovery.test': 'platform_test',
|
'discovery.test': 'platform_test',
|
||||||
@ -232,7 +248,9 @@ class TestHelpersEntityComponent(unittest.TestCase):
|
|||||||
|
|
||||||
@patch('homeassistant.helpers.entity_component.track_utc_time_change')
|
@patch('homeassistant.helpers.entity_component.track_utc_time_change')
|
||||||
def test_set_scan_interval_via_config(self, mock_track):
|
def test_set_scan_interval_via_config(self, mock_track):
|
||||||
|
"""Test the setting of the scan interval via configuration."""
|
||||||
def platform_setup(hass, config, add_devices, discovery_info=None):
|
def platform_setup(hass, config, add_devices, discovery_info=None):
|
||||||
|
"""Test the platform setup."""
|
||||||
add_devices([EntityTest(should_poll=True)])
|
add_devices([EntityTest(should_poll=True)])
|
||||||
|
|
||||||
loader.set_component('test_domain.platform',
|
loader.set_component('test_domain.platform',
|
||||||
@ -252,7 +270,9 @@ class TestHelpersEntityComponent(unittest.TestCase):
|
|||||||
|
|
||||||
@patch('homeassistant.helpers.entity_component.track_utc_time_change')
|
@patch('homeassistant.helpers.entity_component.track_utc_time_change')
|
||||||
def test_set_scan_interval_via_platform(self, mock_track):
|
def test_set_scan_interval_via_platform(self, mock_track):
|
||||||
|
"""Test the setting of the scan interval via platform."""
|
||||||
def platform_setup(hass, config, add_devices, discovery_info=None):
|
def platform_setup(hass, config, add_devices, discovery_info=None):
|
||||||
|
"""Test the platform setup."""
|
||||||
add_devices([EntityTest(should_poll=True)])
|
add_devices([EntityTest(should_poll=True)])
|
||||||
|
|
||||||
platform = MockPlatform(platform_setup)
|
platform = MockPlatform(platform_setup)
|
||||||
|
@ -29,7 +29,7 @@ class TestEventDecoratorHelpers(unittest.TestCase):
|
|||||||
event_decorators.HASS = self.hass
|
event_decorators.HASS = self.hass
|
||||||
|
|
||||||
def tearDown(self): # pylint: disable=invalid-name
|
def tearDown(self): # pylint: disable=invalid-name
|
||||||
""" Stop down stuff we started. """
|
"""Stop everything that was started."""
|
||||||
self.hass.stop()
|
self.hass.stop()
|
||||||
event_decorators.HASS = None
|
event_decorators.HASS = None
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ class TestHomeAssistant(unittest.TestCase):
|
|||||||
self.hass.states.set("switch.AC", "off")
|
self.hass.states.set("switch.AC", "off")
|
||||||
|
|
||||||
def tearDown(self): # pylint: disable=invalid-name
|
def tearDown(self): # pylint: disable=invalid-name
|
||||||
"""Stop down stuff we started."""
|
"""Stop everything that was started."""
|
||||||
try:
|
try:
|
||||||
self.hass.stop()
|
self.hass.stop()
|
||||||
except HomeAssistantError:
|
except HomeAssistantError:
|
||||||
@ -106,7 +106,7 @@ class TestEvent(unittest.TestCase):
|
|||||||
self.assertEqual(event1, event2)
|
self.assertEqual(event1, event2)
|
||||||
|
|
||||||
def test_repr(self):
|
def test_repr(self):
|
||||||
"""Test that repr method works. #MoreCoverage"""
|
"""Test that repr method works."""
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"<Event TestEvent[L]>",
|
"<Event TestEvent[L]>",
|
||||||
str(ha.Event("TestEvent")))
|
str(ha.Event("TestEvent")))
|
||||||
|
@ -216,7 +216,7 @@ class TestRemoteClasses(unittest.TestCase):
|
|||||||
remote.API('127.0.0.1', API_PASSWORD, BROKEN_PORT))
|
remote.API('127.0.0.1', API_PASSWORD, BROKEN_PORT))
|
||||||
|
|
||||||
def test_statemachine_init(self):
|
def test_statemachine_init(self):
|
||||||
""" Tests if remote.StateMachine copies all states on init. """
|
"""Test if remote.StateMachine copies all states on init."""
|
||||||
self.assertEqual(sorted(hass.states.all()),
|
self.assertEqual(sorted(hass.states.all()),
|
||||||
sorted(slave.states.all()))
|
sorted(slave.states.all()))
|
||||||
|
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
"""The tests for the utilities."""
|
@ -62,9 +62,9 @@ class TestUtil(unittest.TestCase):
|
|||||||
|
|
||||||
def test_ordered_enum(self):
|
def test_ordered_enum(self):
|
||||||
"""Test the ordered enum class."""
|
"""Test the ordered enum class."""
|
||||||
|
|
||||||
class TestEnum(util.OrderedEnum):
|
class TestEnum(util.OrderedEnum):
|
||||||
"""Test enum that can be ordered."""
|
"""Test enum that can be ordered."""
|
||||||
|
|
||||||
FIRST = 1
|
FIRST = 1
|
||||||
SECOND = 2
|
SECOND = 2
|
||||||
THIRD = 3
|
THIRD = 3
|
||||||
@ -214,7 +214,6 @@ class TestUtil(unittest.TestCase):
|
|||||||
|
|
||||||
def test_throttle_per_instance(self):
|
def test_throttle_per_instance(self):
|
||||||
"""Test that the throttle method is done per instance of a class."""
|
"""Test that the throttle method is done per instance of a class."""
|
||||||
|
|
||||||
class Tester(object):
|
class Tester(object):
|
||||||
"""A tester class for the throttle."""
|
"""A tester class for the throttle."""
|
||||||
|
|
||||||
@ -228,7 +227,6 @@ class TestUtil(unittest.TestCase):
|
|||||||
|
|
||||||
def test_throttle_on_method(self):
|
def test_throttle_on_method(self):
|
||||||
"""Test that throttle works when wrapping a method."""
|
"""Test that throttle works when wrapping a method."""
|
||||||
|
|
||||||
class Tester(object):
|
class Tester(object):
|
||||||
"""A tester class for the throttle."""
|
"""A tester class for the throttle."""
|
||||||
|
|
||||||
@ -244,7 +242,6 @@ class TestUtil(unittest.TestCase):
|
|||||||
|
|
||||||
def test_throttle_on_two_method(self):
|
def test_throttle_on_two_method(self):
|
||||||
"""Test that throttle works when wrapping two methods."""
|
"""Test that throttle works when wrapping two methods."""
|
||||||
|
|
||||||
class Tester(object):
|
class Tester(object):
|
||||||
"""A test class for the throttle."""
|
"""A test class for the throttle."""
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user