fixing emulated hue issue and testing it (#8928)
* fixing emulated hue issue and testing it * fixing hound issues * I should probably stop using vim * Check against dict directly instead of items.pull/8919/head
parent
956543ae1e
commit
daf7d9ea7f
|
@ -193,6 +193,8 @@ class Config(object):
|
||||||
if entity_id == ent_id:
|
if entity_id == ent_id:
|
||||||
return number
|
return number
|
||||||
|
|
||||||
|
number = '1'
|
||||||
|
if self.numbers:
|
||||||
number = str(max(int(k) for k in self.numbers) + 1)
|
number = str(max(int(k) for k in self.numbers) + 1)
|
||||||
self.numbers[number] = entity_id
|
self.numbers[number] = entity_id
|
||||||
self._save_numbers_json()
|
self._save_numbers_json()
|
||||||
|
|
|
@ -36,6 +36,65 @@ def test_config_google_home_entity_id_to_number():
|
||||||
assert entity_id == 'light.test2'
|
assert entity_id == 'light.test2'
|
||||||
|
|
||||||
|
|
||||||
|
def test_config_google_home_entity_id_to_number_altered():
|
||||||
|
"""Test config adheres to the type."""
|
||||||
|
conf = Config(Mock(), {
|
||||||
|
'type': 'google_home'
|
||||||
|
})
|
||||||
|
|
||||||
|
mop = mock_open(read_data=json.dumps({'21': 'light.test2'}))
|
||||||
|
handle = mop()
|
||||||
|
|
||||||
|
with patch('homeassistant.components.emulated_hue.open', mop, create=True):
|
||||||
|
number = conf.entity_id_to_number('light.test')
|
||||||
|
assert number == '22'
|
||||||
|
assert handle.write.call_count == 1
|
||||||
|
assert json.loads(handle.write.mock_calls[0][1][0]) == {
|
||||||
|
'21': 'light.test2',
|
||||||
|
'22': 'light.test',
|
||||||
|
}
|
||||||
|
|
||||||
|
number = conf.entity_id_to_number('light.test')
|
||||||
|
assert number == '22'
|
||||||
|
assert handle.write.call_count == 1
|
||||||
|
|
||||||
|
number = conf.entity_id_to_number('light.test2')
|
||||||
|
assert number == '21'
|
||||||
|
assert handle.write.call_count == 1
|
||||||
|
|
||||||
|
entity_id = conf.number_to_entity_id('21')
|
||||||
|
assert entity_id == 'light.test2'
|
||||||
|
|
||||||
|
|
||||||
|
def test_config_google_home_entity_id_to_number_empty():
|
||||||
|
"""Test config adheres to the type."""
|
||||||
|
conf = Config(Mock(), {
|
||||||
|
'type': 'google_home'
|
||||||
|
})
|
||||||
|
|
||||||
|
mop = mock_open(read_data='')
|
||||||
|
handle = mop()
|
||||||
|
|
||||||
|
with patch('homeassistant.components.emulated_hue.open', mop, create=True):
|
||||||
|
number = conf.entity_id_to_number('light.test')
|
||||||
|
assert number == '1'
|
||||||
|
assert handle.write.call_count == 1
|
||||||
|
assert json.loads(handle.write.mock_calls[0][1][0]) == {
|
||||||
|
'1': 'light.test',
|
||||||
|
}
|
||||||
|
|
||||||
|
number = conf.entity_id_to_number('light.test')
|
||||||
|
assert number == '1'
|
||||||
|
assert handle.write.call_count == 1
|
||||||
|
|
||||||
|
number = conf.entity_id_to_number('light.test2')
|
||||||
|
assert number == '2'
|
||||||
|
assert handle.write.call_count == 2
|
||||||
|
|
||||||
|
entity_id = conf.number_to_entity_id('2')
|
||||||
|
assert entity_id == 'light.test2'
|
||||||
|
|
||||||
|
|
||||||
def test_config_alexa_entity_id_to_number():
|
def test_config_alexa_entity_id_to_number():
|
||||||
"""Test config adheres to the type."""
|
"""Test config adheres to the type."""
|
||||||
conf = Config(None, {
|
conf = Config(None, {
|
||||||
|
|
Loading…
Reference in New Issue