desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Test sanitize_path.'
def test_sanitize_path(self):
self.assertEqual('test/path', util.sanitize_path('test/path')) self.assertEqual('test/path', util.sanitize_path('~test/path')) self.assertEqual('//test/path', util.sanitize_path('~/../test/path'))
'Test slugify.'
def test_slugify(self):
self.assertEqual('test', util.slugify('T-!@#$!#@$!$est')) self.assertEqual('test_more', util.slugify('Test More')) self.assertEqual('test_more', util.slugify('Test_(More)')) self.assertEqual('test_more', util.slugify('T\xc3\xa8st_M\xc3\xb6r\xc3\xaa')) self.assertEqual('b827eb000000', util.slugify...
'Test repr_helper.'
def test_repr_helper(self):
self.assertEqual('A', util.repr_helper('A')) self.assertEqual('5', util.repr_helper(5)) self.assertEqual('True', util.repr_helper(True)) self.assertEqual('test=1', util.repr_helper({'test': 1})) self.assertEqual('1986-07-09T12:00:00+00:00', util.repr_helper(datetime(1986, 7, 9, 12, 0, 0)))
'Test convert.'
def test_convert(self):
self.assertEqual(5, util.convert('5', int)) self.assertEqual(5.0, util.convert('5', float)) self.assertEqual(True, util.convert('True', bool)) self.assertEqual(1, util.convert('NOT A NUMBER', int, 1)) self.assertEqual(1, util.convert(None, int, 1)) self.assertEqual(1, util.convert(object, ...
'Test ensure_unique_string.'
def test_ensure_unique_string(self):
self.assertEqual('Beer_3', util.ensure_unique_string('Beer', ['Beer', 'Beer_2'])) self.assertEqual('Beer', util.ensure_unique_string('Beer', ['Wine', 'Soda']))
'Test the ordered enum class.'
def test_ordered_enum(self):
class TestEnum(util.OrderedEnum, ): 'Test enum that can be ordered.' FIRST = 1 SECOND = 2 THIRD = 3 self.assertTrue((TestEnum.SECOND >= TestEnum.FIRST)) self.assertTrue((TestEnum.SECOND >= TestEnum.SECOND)) self.assertFalse((TestEnum.SECOND >= TestEnum.THIR...
'Test ordering of set.'
def test_ordered_set(self):
set1 = util.OrderedSet([1, 2, 3, 4]) set2 = util.OrderedSet([3, 4, 5]) self.assertEqual(4, len(set1)) self.assertEqual(3, len(set2)) self.assertIn(1, set1) self.assertIn(2, set1) self.assertIn(3, set1) self.assertIn(4, set1) self.assertNotIn(5, set1) self.assertNotIn(1, set2) ...
'Test the add cooldown decorator.'
def test_throttle(self):
calls1 = [] calls2 = [] @util.Throttle(timedelta(seconds=4)) def test_throttle1(): calls1.append(1) @util.Throttle(timedelta(seconds=4), timedelta(seconds=2)) def test_throttle2(): calls2.append(1) now = dt_util.utcnow() plus3 = (now + timedelta(seconds=3)) plus5 = (p...
'Test that the throttle method is done per instance of a class.'
def test_throttle_per_instance(self):
class Tester(object, ): 'A tester class for the throttle.' @util.Throttle(timedelta(seconds=1)) def hello(self): 'Test the throttle.' return True self.assertTrue(Tester().hello()) self.assertTrue(Tester().hello())
'Test that throttle works when wrapping a method.'
def test_throttle_on_method(self):
class Tester(object, ): 'A tester class for the throttle.' def hello(self): 'Test the throttle.' return True tester = Tester() throttled = util.Throttle(timedelta(seconds=1))(tester.hello) self.assertTrue(throttled()) self.assertIsNone(thr...
'Test that throttle works when wrapping two methods.'
def test_throttle_on_two_method(self):
class Tester(object, ): 'A test class for the throttle.' @util.Throttle(timedelta(seconds=1)) def hello(self): 'Test the throttle.' return True @util.Throttle(timedelta(seconds=1)) def goodbye(self): 'Test the thr...
'Test conversion from any unit to same unit.'
def test_convert_same_unit(self):
self.assertEqual(5, distance_util.convert(5, LENGTH_KILOMETERS, LENGTH_KILOMETERS)) self.assertEqual(2, distance_util.convert(2, LENGTH_METERS, LENGTH_METERS)) self.assertEqual(10, distance_util.convert(10, LENGTH_MILES, LENGTH_MILES)) self.assertEqual(9, distance_util.convert(9, LENGTH_FEET, LENGTH_FEE...
'Test exception is thrown for invalid units.'
def test_convert_invalid_unit(self):
with self.assertRaises(ValueError): distance_util.convert(5, INVALID_SYMBOL, VALID_SYMBOL) with self.assertRaises(ValueError): distance_util.convert(5, VALID_SYMBOL, INVALID_SYMBOL)
'Test exception is thrown for nonnumeric type.'
def test_convert_nonnumeric_value(self):
with self.assertRaises(TypeError): distance_util.convert('a', LENGTH_KILOMETERS, LENGTH_METERS)
'Test conversion from miles to other units.'
def test_convert_from_miles(self):
miles = 5 self.assertEqual(distance_util.convert(miles, LENGTH_MILES, LENGTH_KILOMETERS), 8.04672) self.assertEqual(distance_util.convert(miles, LENGTH_MILES, LENGTH_METERS), 8046.72) self.assertEqual(distance_util.convert(miles, LENGTH_MILES, LENGTH_FEET), 26400.0008448)
'Test conversion from feet to other units.'
def test_convert_from_feet(self):
feet = 5000 self.assertEqual(distance_util.convert(feet, LENGTH_FEET, LENGTH_KILOMETERS), 1.524) self.assertEqual(distance_util.convert(feet, LENGTH_FEET, LENGTH_METERS), 1524) self.assertEqual(distance_util.convert(feet, LENGTH_FEET, LENGTH_MILES), 0.9469694040000001)
'Test conversion from kilometers to other units.'
def test_convert_from_kilometers(self):
km = 5 self.assertEqual(distance_util.convert(km, LENGTH_KILOMETERS, LENGTH_FEET), 16404.2) self.assertEqual(distance_util.convert(km, LENGTH_KILOMETERS, LENGTH_METERS), 5000) self.assertEqual(distance_util.convert(km, LENGTH_KILOMETERS, LENGTH_MILES), 3.106855)
'Test conversion from meters to other units.'
def test_convert_from_meters(self):
m = 5000 self.assertEqual(distance_util.convert(m, LENGTH_METERS, LENGTH_FEET), 16404.2) self.assertEqual(distance_util.convert(m, LENGTH_METERS, LENGTH_KILOMETERS), 5) self.assertEqual(distance_util.convert(m, LENGTH_METERS, LENGTH_MILES), 3.106855)
'Setup the tests.'
def setUp(self):
self.orig_default_time_zone = dt_util.DEFAULT_TIME_ZONE
'Stop everything that was started.'
def tearDown(self):
dt_util.set_default_time_zone(self.orig_default_time_zone)
'Test getting a time zone.'
def test_get_time_zone_retrieves_valid_time_zone(self):
time_zone = dt_util.get_time_zone(TEST_TIME_ZONE) self.assertIsNotNone(time_zone) self.assertEqual(TEST_TIME_ZONE, time_zone.zone)
'Test getting a non existing time zone.'
def test_get_time_zone_returns_none_for_garbage_time_zone(self):
time_zone = dt_util.get_time_zone('Non existing time zone') self.assertIsNone(time_zone)
'Test setting default time zone.'
def test_set_default_time_zone(self):
time_zone = dt_util.get_time_zone(TEST_TIME_ZONE) dt_util.set_default_time_zone(time_zone) self.assertEqual(time_zone.zone, dt_util.now().tzinfo.zone)
'Test the UTC now method.'
def test_utcnow(self):
self.assertAlmostEqual(dt_util.utcnow().replace(tzinfo=None), datetime.utcnow(), delta=timedelta(seconds=1))
'Test the now method.'
def test_now(self):
dt_util.set_default_time_zone(dt_util.get_time_zone(TEST_TIME_ZONE)) self.assertAlmostEqual(dt_util.as_utc(dt_util.now()).replace(tzinfo=None), datetime.utcnow(), delta=timedelta(seconds=1))
'Test the now method.'
def test_as_utc_with_naive_object(self):
utcnow = datetime.utcnow() self.assertEqual(utcnow, dt_util.as_utc(utcnow).replace(tzinfo=None))
'Test UTC time with UTC object.'
def test_as_utc_with_utc_object(self):
utcnow = dt_util.utcnow() self.assertEqual(utcnow, dt_util.as_utc(utcnow))
'Test the UTC time with local object.'
def test_as_utc_with_local_object(self):
dt_util.set_default_time_zone(dt_util.get_time_zone(TEST_TIME_ZONE)) localnow = dt_util.now() utcnow = dt_util.as_utc(localnow) self.assertEqual(localnow, utcnow) self.assertNotEqual(localnow.tzinfo, utcnow.tzinfo)
'Test local time with native object.'
def test_as_local_with_naive_object(self):
now = dt_util.now() self.assertAlmostEqual(now, dt_util.as_local(datetime.utcnow()), delta=timedelta(seconds=1))
'Test local with local object.'
def test_as_local_with_local_object(self):
now = dt_util.now() self.assertEqual(now, now)
'Test local time with UTC object.'
def test_as_local_with_utc_object(self):
dt_util.set_default_time_zone(dt_util.get_time_zone(TEST_TIME_ZONE)) utcnow = dt_util.utcnow() localnow = dt_util.as_local(utcnow) self.assertEqual(localnow, utcnow) self.assertNotEqual(localnow.tzinfo, utcnow.tzinfo)
'Test utc_from_timestamp method.'
def test_utc_from_timestamp(self):
self.assertEqual(datetime(1986, 7, 9, tzinfo=dt_util.UTC), dt_util.utc_from_timestamp(521251200))
'Test as_timestamp method.'
def test_as_timestamp(self):
ts = 1462401234 utc_dt = dt_util.utc_from_timestamp(ts) self.assertEqual(ts, dt_util.as_timestamp(utc_dt)) utc_iso = utc_dt.isoformat() self.assertEqual(ts, dt_util.as_timestamp(utc_iso)) delta = dt_util.as_timestamp('2016-01-01 12:12:12') delta -= dt_util.as_timestamp('2016-01-01 12:1...
'Test parse_datetime converts strings.'
def test_parse_datetime_converts_correctly(self):
assert (datetime(1986, 7, 9, 12, 0, 0, tzinfo=dt_util.UTC) == dt_util.parse_datetime('1986-07-09T12:00:00Z')) utcnow = dt_util.utcnow() assert (utcnow == dt_util.parse_datetime(utcnow.isoformat()))
'Test parse_datetime returns None if incorrect format.'
def test_parse_datetime_returns_none_for_incorrect_format(self):
self.assertIsNone(dt_util.parse_datetime('not a datetime string'))
'Test get_age.'
def test_get_age(self):
diff = (dt_util.now() - timedelta(seconds=0)) self.assertEqual(dt_util.get_age(diff), '0 seconds') diff = (dt_util.now() - timedelta(seconds=1)) self.assertEqual(dt_util.get_age(diff), '1 second') diff = (dt_util.now() - timedelta(seconds=30)) self.assertEqual(dt_util.get_age(diff), '30 ...
'Test simple list.'
def test_simple_list(self):
conf = 'config:\n - simple\n - list' with io.StringIO(conf) as file: doc = yaml.yaml.safe_load(file) assert (doc['config'] == ['simple', 'list'])
'Test simple dict.'
def test_simple_dict(self):
conf = 'key: value' with io.StringIO(conf) as file: doc = yaml.yaml.safe_load(file) assert (doc['key'] == 'value')
'Test an unhasable key.'
def test_unhashable_key(self):
files = {YAML_CONFIG_FILE: 'message:\n {{ states.state }}'} with self.assertRaises(HomeAssistantError): with patch_yaml_files(files): load_yaml_config_file(YAML_CONFIG_FILE)
'Test item without an key.'
def test_no_key(self):
files = {YAML_CONFIG_FILE: 'a: a\nnokeyhere'} with self.assertRaises(HomeAssistantError): with patch_yaml_files(files): yaml.load_yaml(YAML_CONFIG_FILE)
'Test config file with enviroment variable.'
def test_enviroment_variable(self):
os.environ['PASSWORD'] = 'secret_password' conf = 'password: !env_var PASSWORD' with io.StringIO(conf) as file: doc = yaml.yaml.safe_load(file) assert (doc['password'] == 'secret_password') del os.environ['PASSWORD']
'Test config file with default value for environment variable.'
def test_environment_variable_default(self):
conf = 'password: !env_var PASSWORD secret_password' with io.StringIO(conf) as file: doc = yaml.yaml.safe_load(file) assert (doc['password'] == 'secret_password')
'Test config file with no enviroment variable sat.'
def test_invalid_enviroment_variable(self):
conf = 'password: !env_var PASSWORD' with self.assertRaises(HomeAssistantError): with io.StringIO(conf) as file: yaml.yaml.safe_load(file)
'Test include yaml.'
def test_include_yaml(self):
with patch_yaml_files({'test.yaml': 'value'}): conf = 'key: !include test.yaml' with io.StringIO(conf) as file: doc = yaml.yaml.safe_load(file) assert (doc['key'] == 'value') with patch_yaml_files({'test.yaml': None}): conf = 'key: !include test.yaml' ...
'Test include dir list yaml.'
@patch('homeassistant.util.yaml.os.walk') def test_include_dir_list(self, mock_walk):
mock_walk.return_value = [['/tmp', [], ['one.yaml', 'two.yaml']]] with patch_yaml_files({'/tmp/one.yaml': 'one', '/tmp/two.yaml': 'two'}): conf = 'key: !include_dir_list /tmp' with io.StringIO(conf) as file: doc = yaml.yaml.safe_load(file) assert (sorted(doc['key'])...
'Test include dir recursive list yaml.'
@patch('homeassistant.util.yaml.os.walk') def test_include_dir_list_recursive(self, mock_walk):
mock_walk.return_value = [['/tmp', ['tmp2', '.ignore', 'ignore'], ['zero.yaml']], ['/tmp/tmp2', [], ['one.yaml', 'two.yaml']], ['/tmp/ignore', [], ['.ignore.yaml']]] with patch_yaml_files({'/tmp/zero.yaml': 'zero', '/tmp/tmp2/one.yaml': 'one', '/tmp/tmp2/two.yaml': 'two'}): conf = 'key: !include_dir_...
'Test include dir named yaml.'
@patch('homeassistant.util.yaml.os.walk') def test_include_dir_named(self, mock_walk):
mock_walk.return_value = [['/tmp', [], ['first.yaml', 'second.yaml']]] with patch_yaml_files({'/tmp/first.yaml': 'one', '/tmp/second.yaml': 'two'}): conf = 'key: !include_dir_named /tmp' correct = {'first': 'one', 'second': 'two'} with io.StringIO(conf) as file: doc = y...
'Test include dir named yaml.'
@patch('homeassistant.util.yaml.os.walk') def test_include_dir_named_recursive(self, mock_walk):
mock_walk.return_value = [['/tmp', ['tmp2', '.ignore', 'ignore'], ['first.yaml']], ['/tmp/tmp2', [], ['second.yaml', 'third.yaml']], ['/tmp/ignore', [], ['.ignore.yaml']]] with patch_yaml_files({'/tmp/first.yaml': 'one', '/tmp/tmp2/second.yaml': 'two', '/tmp/tmp2/third.yaml': 'three'}): conf = 'key: ...
'Test include dir merge list yaml.'
@patch('homeassistant.util.yaml.os.walk') def test_include_dir_merge_list(self, mock_walk):
mock_walk.return_value = [['/tmp', [], ['first.yaml', 'second.yaml']]] with patch_yaml_files({'/tmp/first.yaml': '- one', '/tmp/second.yaml': '- two\n- three'}): conf = 'key: !include_dir_merge_list /tmp' with io.StringIO(conf) as file: doc = yaml.yaml.safe_load(file) ...
'Test include dir merge list yaml.'
@patch('homeassistant.util.yaml.os.walk') def test_include_dir_merge_list_recursive(self, mock_walk):
mock_walk.return_value = [['/tmp', ['tmp2', '.ignore', 'ignore'], ['first.yaml']], ['/tmp/tmp2', [], ['second.yaml', 'third.yaml']], ['/tmp/ignore', [], ['.ignore.yaml']]] with patch_yaml_files({'/tmp/first.yaml': '- one', '/tmp/tmp2/second.yaml': '- two', '/tmp/tmp2/third.yaml': '- three\n- four'})...
'Test include dir merge named yaml.'
@patch('homeassistant.util.yaml.os.walk') def test_include_dir_merge_named(self, mock_walk):
mock_walk.return_value = [['/tmp', [], ['first.yaml', 'second.yaml']]] files = {'/tmp/first.yaml': 'key1: one', '/tmp/second.yaml': 'key2: two\nkey3: three'} with patch_yaml_files(files): conf = 'key: !include_dir_merge_named /tmp' with io.StringIO(conf) as file: d...
'Test include dir merge named yaml.'
@patch('homeassistant.util.yaml.os.walk') def test_include_dir_merge_named_recursive(self, mock_walk):
mock_walk.return_value = [['/tmp', ['tmp2', '.ignore', 'ignore'], ['first.yaml']], ['/tmp/tmp2', [], ['second.yaml', 'third.yaml']], ['/tmp/ignore', [], ['.ignore.yaml']]] with patch_yaml_files({'/tmp/first.yaml': 'key1: one', '/tmp/tmp2/second.yaml': 'key2: two', '/tmp/tmp2/third.yaml': 'key3: three\n...
'Test raising a UnicodeDecodeError.'
@patch('homeassistant.util.yaml.open', create=True) def test_load_yaml_encoding_error(self, mock_open):
mock_open.side_effect = UnicodeDecodeError('', '', 1, 0, '') self.assertRaises(HomeAssistantError, yaml.load_yaml, 'test')
'The that the dump method returns empty None values.'
def test_dump(self):
assert (yaml.dump({'a': None, 'b': 'b'}) == 'a:\nb: b\n')
'Store keyring dictionary.'
def __init__(self, secrets_dict):
self._secrets = secrets_dict
'Retrieve password.'
def get_password(self, domain, name):
assert (domain == yaml._SECRET_NAMESPACE) return self._secrets.get(name)
'Create & load secrets file.'
def setUp(self):
config_dir = get_test_config_dir() yaml.clear_secret_cache() self._yaml_path = os.path.join(config_dir, YAML_CONFIG_FILE) self._secret_path = os.path.join(config_dir, yaml._SECRET_YAML) self._sub_folder_path = os.path.join(config_dir, 'subFolder') self._unrelated_path = os.path.join(config_dir, ...
'Clean up secrets.'
def tearDown(self):
yaml.clear_secret_cache() FILES.clear()
'Did secrets load ok.'
def test_secrets_from_yaml(self):
expected = {'api_password': 'pwhttp'} self.assertEqual(expected, self._yaml['http']) expected = {'username': 'un1', 'password': 'pw1'} self.assertEqual(expected, self._yaml['component'])
'Test loading secrets from parent foler.'
def test_secrets_from_parent_folder(self):
expected = {'api_password': 'pwhttp'} self._yaml = load_yaml(os.path.join(self._sub_folder_path, 'sub.yaml'), 'http:\n api_password: !secret http_pw\ncomponent:\n username: !secret comp1_un\n password: !secret comp1_pw\n') self.assertEqual(expected, self._yaml['http'])...
'Test loading current directory secret overrides the parent.'
def test_secret_overrides_parent(self):
expected = {'api_password': 'override'} load_yaml(os.path.join(self._sub_folder_path, yaml._SECRET_YAML), 'http_pw: override') self._yaml = load_yaml(os.path.join(self._sub_folder_path, 'sub.yaml'), 'http:\n api_password: !secret http_pw\ncomponent:\n username: !secret comp1_un\...
'Test loading secrets from unrelated folder fails.'
def test_secrets_from_unrelated_fails(self):
load_yaml(os.path.join(self._unrelated_path, yaml._SECRET_YAML), 'test: failure') with self.assertRaises(HomeAssistantError): load_yaml(os.path.join(self._sub_folder_path, 'sub.yaml'), 'http:\n api_password: !secret test')
'Test keyring fallback & get_password.'
def test_secrets_keyring(self):
yaml.keyring = None yaml_str = 'http:\n api_password: !secret http_pw_keyring' with self.assertRaises(yaml.HomeAssistantError): load_yaml(self._yaml_path, yaml_str) yaml.keyring = FakeKeyring({'http_pw_keyring': 'yeah'}) _yaml = load_yaml(self._yaml_path, yaml_str) self.asse...
'Test credstash fallback & get_password.'
@patch.object(yaml, 'credstash') def test_secrets_credstash(self, mock_credstash):
mock_credstash.getSecret.return_value = 'yeah' yaml_str = 'http:\n api_password: !secret http_pw_credstash' _yaml = load_yaml(self._yaml_path, yaml_str) log = logging.getLogger() log.error(_yaml['http']) self.assertEqual({'api_password': 'yeah'}, _yaml['http'])
'Ensure logger: debug was removed.'
def test_secrets_logger_removed(self):
with self.assertRaises(yaml.HomeAssistantError): load_yaml(self._yaml_path, 'api_password: !secret logger')
'Ensure logger: debug was removed.'
@patch('homeassistant.util.yaml._LOGGER.error') def test_bad_logger_value(self, mock_error):
yaml.clear_secret_cache() load_yaml(self._secret_path, 'logger: info\npw: abc') load_yaml(self._yaml_path, 'api_password: !secret pw') assert (mock_error.call_count == 1), 'Expected an error about logger: value'
'Test icon generator for battery sensor.'
def test_battery_icon(self):
from homeassistant.util.icon import icon_for_battery_level self.assertEqual('mdi:battery-unknown', icon_for_battery_level(None, True)) self.assertEqual('mdi:battery-unknown', icon_for_battery_level(None, False)) self.assertEqual('mdi:battery-outline', icon_for_battery_level(5, True)) self.assertEqua...
'Initialize test image processing.'
def __init__(self, camera_entity, name):
self._name = name self._camera = camera_entity self._count = 0 self._image = ''
'Return True if entity has to be polled for state.'
@property def should_poll(self):
return False
'Return camera entity id from process pictures.'
@property def camera_entity(self):
return self._camera
'Return the name of the entity.'
@property def name(self):
return self._name
'Return the state of the entity.'
@property def state(self):
return self._count
'Return device specific state attributes.'
@property def device_state_attributes(self):
return {'image': self._image}
'Process image.'
def process_image(self, image):
self._image = image self._count += 1
'Initialize the MockScanner.'
def __init__(self):
self.devices_home = []
'Make a device come home.'
def come_home(self, device):
self.devices_home.append(device)
'Make a device leave the house.'
def leave_home(self, device):
self.devices_home.remove(device)
'Reset which devices are home.'
def reset(self):
self.devices_home = []
'Return a list of fake devices.'
def scan_devices(self):
return list(self.devices_home)
'Return a name for a mock device. Return None for dev1 for testing.'
def get_device_name(self, device):
return (None if (device == 'DEV1') else device.lower())
'Init the error.'
def __init__(self, exception):
super().__init__('{}: {}'.format(exception.__class__.__name__, exception))
'Initialize the Z-Wave fan device.'
def __init__(self, values):
zwave.ZWaveDeviceEntity.__init__(self, values, DOMAIN) self.update_properties()
'Handle data changes for node values.'
def update_properties(self):
value = math.ceil(((self.values.primary.data * 3) / 100)) self._state = VALUE_TO_SPEED[value]
'Set the speed of the fan.'
def set_speed(self, speed):
self.node.set_dimmer(self.values.primary.value_id, SPEED_TO_VALUE[speed])
'Turn the device on.'
def turn_on(self, speed=None, **kwargs):
if (speed is None): self.node.set_dimmer(self.values.primary.value_id, 255) else: self.set_speed(speed)
'Turn the device off.'
def turn_off(self, **kwargs):
self.node.set_dimmer(self.values.primary.value_id, 0)
'Return the current speed.'
@property def speed(self):
return self._state
'Get the list of available speeds.'
@property def speed_list(self):
return SPEED_LIST
'Flag supported features.'
@property def supported_features(self):
return SUPPORTED_FEATURES
'Init Nest Devices.'
def __init__(self, hass, conf, nest):
self.hass = hass self.nest = nest if (CONF_STRUCTURE not in conf): self.local_structure = [s.name for s in nest.structures] else: self.local_structure = conf[CONF_STRUCTURE] _LOGGER.debug('Structures to include: %s', self.local_structure)
'Generate a list of thermostats and their location.'
def thermostats(self):
try: for structure in self.nest.structures: if (structure.name in self.local_structure): for device in structure.thermostats: (yield (structure, device)) else: _LOGGER.debug('Ignoring structure %s, not in %s', structu...
'Generate a list of smoke co alarams.'
def smoke_co_alarms(self):
try: for structure in self.nest.structures: if (structure.name in self.local_structure): for device in structure.smoke_co_alarms: (yield (structure, device)) else: _LOGGER.info('Ignoring structure %s, not in %s', stru...
'Generate a list of cameras.'
def cameras(self):
try: for structure in self.nest.structures: if (structure.name in self.local_structure): for device in structure.cameras: (yield (structure, device)) else: _LOGGER.info('Ignoring structure %s, not in %s', structure.na...
'Flag supported features.'
@property def supported_features(self):
return ((SUPPORT_OPEN | SUPPORT_CLOSE) | SUPPORT_SET_POSITION)
'Return if the cover is closed.'
@property def is_closed(self):
return (self._state['current_state'] < 1)
'Return the current position of cover.'
@property def current_cover_position(self):
return self._state['current_state']
'Close the cover.'
def close_cover(self):
self._smartbridge.set_value(self._device_id, 0)
'Open the cover.'
def open_cover(self):
self._smartbridge.set_value(self._device_id, 100)
'Move the roller shutter to a specific position.'
def set_cover_position(self, position, **kwargs):
self._smartbridge.set_value(self._device_id, position)
'Call when forcing a refresh of the device.'
def update(self):
self._state = self._smartbridge.get_device_by_id(self._device_id) _LOGGER.debug(self._state)