mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Fix broken tests + linting
This commit is contained in:
parent
a91f937245
commit
3ac31b2c1b
@ -89,8 +89,7 @@ class BinarySensorTemplate(BinarySensorDevice):
|
|||||||
|
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def template_bsensor_state_listener(self, entity, old_state,
|
def template_bsensor_state_listener(entity, old_state, new_state):
|
||||||
new_state):
|
|
||||||
"""Called when the target device changes state."""
|
"""Called when the target device changes state."""
|
||||||
self.update_ha_state(True)
|
self.update_ha_state(True)
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ class SensorTemplate(Entity):
|
|||||||
|
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def template_sensor_state_listener(self, entity, old_state, new_state):
|
def template_sensor_state_listener(entity, old_state, new_state):
|
||||||
"""Called when the target device changes state."""
|
"""Called when the target device changes state."""
|
||||||
self.update_ha_state(True)
|
self.update_ha_state(True)
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ class SwitchTemplate(SwitchDevice):
|
|||||||
|
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def template_switch_state_listener(self, entity, old_state, new_state):
|
def template_switch_state_listener(entity, old_state, new_state):
|
||||||
"""Called when the target device changes state."""
|
"""Called when the target device changes state."""
|
||||||
self.update_ha_state(True)
|
self.update_ha_state(True)
|
||||||
|
|
||||||
|
@ -32,23 +32,23 @@ def track_state_change(hass, entity_ids, action, from_state=None,
|
|||||||
def state_change_listener(event):
|
def state_change_listener(event):
|
||||||
"""The listener that listens for specific state changes."""
|
"""The listener that listens for specific state changes."""
|
||||||
if entity_ids != MATCH_ALL and \
|
if entity_ids != MATCH_ALL and \
|
||||||
event.data['entity_id'] not in entity_ids:
|
event.data.get('entity_id') not in entity_ids:
|
||||||
return
|
return
|
||||||
|
|
||||||
if event.data['old_state'] is None:
|
if event.data.get('old_state') is not None:
|
||||||
old_state = None
|
|
||||||
else:
|
|
||||||
old_state = event.data['old_state'].state
|
old_state = event.data['old_state'].state
|
||||||
|
|
||||||
if event.data['new_state'] is None:
|
|
||||||
new_state = None
|
|
||||||
else:
|
else:
|
||||||
|
old_state = None
|
||||||
|
|
||||||
|
if event.data.get('new_state') is not None:
|
||||||
new_state = event.data['new_state'].state
|
new_state = event.data['new_state'].state
|
||||||
|
else:
|
||||||
|
new_state = None
|
||||||
|
|
||||||
if _matcher(old_state, from_state) and _matcher(new_state, to_state):
|
if _matcher(old_state, from_state) and _matcher(new_state, to_state):
|
||||||
action(event.data['entity_id'],
|
action(event.data.get('entity_id'),
|
||||||
event.data['old_state'],
|
event.data.get('old_state'),
|
||||||
event.data['new_state'])
|
event.data.get('new_state'))
|
||||||
|
|
||||||
hass.bus.listen(EVENT_STATE_CHANGED, state_change_listener)
|
hass.bus.listen(EVENT_STATE_CHANGED, state_change_listener)
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import unittest
|
import unittest
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
from homeassistant.const import EVENT_STATE_CHANGED
|
from homeassistant.const import EVENT_STATE_CHANGED, MATCH_ALL
|
||||||
from homeassistant.components.binary_sensor import template
|
from homeassistant.components.binary_sensor import template
|
||||||
from homeassistant.exceptions import TemplateError
|
from homeassistant.exceptions import TemplateError
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ class TestBinarySensorTemplate(unittest.TestCase):
|
|||||||
result = template.setup_platform(hass, config, add_devices)
|
result = template.setup_platform(hass, config, add_devices)
|
||||||
self.assertTrue(result)
|
self.assertTrue(result)
|
||||||
mock_template.assert_called_once_with(hass, 'test', 'virtual thingy',
|
mock_template.assert_called_once_with(hass, 'test', 'virtual thingy',
|
||||||
'motion', '{{ foo }}', None)
|
'motion', '{{ foo }}', MATCH_ALL)
|
||||||
add_devices.assert_called_once_with([mock_template.return_value])
|
add_devices.assert_called_once_with([mock_template.return_value])
|
||||||
|
|
||||||
def test_setup_no_sensors(self):
|
def test_setup_no_sensors(self):
|
||||||
@ -77,7 +77,7 @@ class TestBinarySensorTemplate(unittest.TestCase):
|
|||||||
""""Test the attributes."""
|
""""Test the attributes."""
|
||||||
hass = mock.MagicMock()
|
hass = mock.MagicMock()
|
||||||
vs = template.BinarySensorTemplate(hass, 'parent', 'Parent',
|
vs = template.BinarySensorTemplate(hass, 'parent', 'Parent',
|
||||||
'motion', '{{ 1 > 1 }}', None)
|
'motion', '{{ 1 > 1 }}', MATCH_ALL)
|
||||||
self.assertFalse(vs.should_poll)
|
self.assertFalse(vs.should_poll)
|
||||||
self.assertEqual('motion', vs.sensor_class)
|
self.assertEqual('motion', vs.sensor_class)
|
||||||
self.assertEqual('Parent', vs.name)
|
self.assertEqual('Parent', vs.name)
|
||||||
@ -93,7 +93,7 @@ class TestBinarySensorTemplate(unittest.TestCase):
|
|||||||
""""Test the event."""
|
""""Test the event."""
|
||||||
hass = get_test_home_assistant()
|
hass = get_test_home_assistant()
|
||||||
vs = template.BinarySensorTemplate(hass, 'parent', 'Parent',
|
vs = template.BinarySensorTemplate(hass, 'parent', 'Parent',
|
||||||
'motion', '{{ 1 > 1 }}', None)
|
'motion', '{{ 1 > 1 }}', MATCH_ALL)
|
||||||
vs.update_ha_state()
|
vs.update_ha_state()
|
||||||
hass.pool.block_till_done()
|
hass.pool.block_till_done()
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ class TestBinarySensorTemplate(unittest.TestCase):
|
|||||||
""""Test the template update error."""
|
""""Test the template update error."""
|
||||||
hass = mock.MagicMock()
|
hass = mock.MagicMock()
|
||||||
vs = template.BinarySensorTemplate(hass, 'parent', 'Parent',
|
vs = template.BinarySensorTemplate(hass, 'parent', 'Parent',
|
||||||
'motion', '{{ 1 > 1 }}', None)
|
'motion', '{{ 1 > 1 }}', MATCH_ALL)
|
||||||
mock_render.side_effect = TemplateError('foo')
|
mock_render.side_effect = TemplateError('foo')
|
||||||
vs.update()
|
vs.update()
|
||||||
mock_render.side_effect = TemplateError(
|
mock_render.side_effect = TemplateError(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user