Compare commits

..

23 Commits

Author SHA1 Message Date
Paulus Schoutsen
f55ab9d4ea Merge pull request #19391 from home-assistant/rc
0.84.3
2018-12-17 12:44:50 +01:00
Paulus Schoutsen
23cc4d1453 Bumped version to 0.84.3 2018-12-17 10:46:39 +01:00
Glen Takahashi
f613cd38fc Fix not being able to update entities (#19344)
When editing an entity in the frontend dialog, pressing save causes a "save failed: Entity is already registered" error. This is because the frontend always sets `name` and `new_entity_id` in the websocket command even if they haven't been changed. This adds a check that the `new_entity_id` is actually different from `entity_id` before erroring that the `new_entity_id` is already registered.
2018-12-17 10:46:31 +01:00
liaanvdm
45238295df Fix restore state for manual alarm control panel (#19284)
* Fixed manual alarm control panel restore state

* Revert "Fixed manual alarm control panel restore state"

This reverts commit 61c9faf434.

* Fixed manual alarm control panel's state restore
2018-12-17 10:46:31 +01:00
Andrew Hayworth
65bd308491 Set lock status correctly for Schlage BE469 Z-Wave locks (#18737)
* Set lock status correctly for Schlage BE469 Z-Wave locks

PR #17386 attempted to improve the state of z-wave lock tracking for
some problematic models. However, it operated under a flawed
assumptions. Namely, that we can always trust `self.values` to have
fresh data, and that the Schlage BE469 sends alarm reports after every
lock event. We can't trust `self.values`, and the Schlage is very
broken. :)

When we receive a notification from the driver about a state change,
we call `update_properties` - but we can (and do!) have _stale_
properties left over from previous updates. #17386 really works best
if you start from a clean slate each time. However, `update_properties`
is called on every value update, and we don't get a reason why.
Moreover, values that weren't just refreshed are not removed. So blindly
looking at something like `self.values.access_control` when deciding to
apply a workaround is not going to always be correct - it may or may not
be, depending on what happened in the past.

For the sad case of the BE469, here are the Z-Wave events that happen
under various circumstances:

RF Lock / Unlock:
- Send: door lock command set
- Receive: door lock report
- Send: door lock command get
- Receive: door lock report

Manual lock / Unlock:
- Receive: alarm
- Send: door lock command get
- Receive: door lock report

Keypad lock / Unlock:
- Receive: alarm
- Send: door lock command get
- Receive: door lock report

Thus, this PR introduces yet another work around - we track the current
and last z-wave command that the driver saw, and make assumptions based
on the sequence of events. This seems to be the most reliable way to go
- simply asking the driver to refresh various states doesn't clear out
alarms the way you would expect; this model doesn't support the access
control logging commands; and trying to manually clear out alarm state
when calling RF lock/unlock was tricky.

The lock state, when the z-wave network restarts, may look out of sync
for a few minutes. However, after the full network restart is complete,
everything looks good in my testing.

* Fix linter
2018-12-17 10:46:30 +01:00
Paulus Schoutsen
30345489e6 Updated frontend to 20181211.1 2018-12-17 10:21:24 +01:00
Paulus Schoutsen
1135446de4 Merge pull request #19281 from home-assistant/rc
0.84.2
2018-12-14 11:19:41 +01:00
emontnemery
a262d0f9e4 Fix race in entity_platform.async_add_entities (#19222) 2018-12-14 10:34:02 +01:00
Paulus Schoutsen
d425aabae3 Bumped version to 0.84.2 2018-12-14 10:27:45 +01:00
Eric Nagley
8d44b721c6 Fix call to super() (#19279)
* home-assistant/home-assistant#19273: fix call to super()

* home-assistant/home-assistant#19273: adjust to python3 standards.

* home-assistant/home-assistant#19273: remove bad test.
2018-12-14 10:27:37 +01:00
Paulus Schoutsen
baa1801e13 Fix OwnTracks deadlocking (#19260)
* Fix OwnTracks deadlocking

* Fix deadlock
2018-12-14 10:27:36 +01:00
Fabian Affolter
965e47eb6a Fix list (fixes #19235) (#19258) 2018-12-14 10:27:35 +01:00
Luca Angemi
16c0301227 Add automation and script events to logbook filter events (#19253)
* Add automation and script events to logbook filter events

* Update logbook.py

* Update logbook.py

* Update logbook tests

* Update test_logbook.py

* Update test_logbook.py

* Update test_logbook.py

* Update test_logbook.py
2018-12-14 10:27:35 +01:00
kennedyshead
37096a2b65 Bump aioasuswrt (#19229)
* bump aioasuswrt version

* run gen_requirements
2018-12-14 10:27:34 +01:00
Erik
bead08840e Review comments 2018-12-14 10:27:13 +01:00
Erik
b7b55f941c Move check to websocket 2018-12-14 10:27:13 +01:00
Erik
4231775e04 Fail if new entity_id is in hass.states 2018-12-14 10:27:13 +01:00
damarco
14d90b5484 Always add friendly name attribute to ZHA entities (#19141)
* Always add friendly name attribute

* Only change device_info name
2018-12-14 10:25:41 +01:00
Sebastian Muszynski
afa48c54e9 Don't avoid async_schedule_update_ha_state by returning false (#19102) 2018-12-14 10:25:40 +01:00
Paulus Schoutsen
6603b3eccd Merge pull request #19228 from home-assistant/rc
0.84.1
2018-12-12 17:54:37 +01:00
Paulus Schoutsen
e2bf3ac095 Bumped version to 0.84.1 2018-12-12 17:18:47 +01:00
Paulus Schoutsen
ced96775fe Fix owntracks topic in encrypted ios (#19220)
* Fix owntracks topic

* Warn if per-topic secret and using HTTP
2018-12-12 17:18:38 +01:00
Jason Hunter
f65e57bf7b Add automation and script events to logbook event types (#19219) 2018-12-12 17:18:37 +01:00
20 changed files with 183 additions and 50 deletions

View File

@@ -310,7 +310,15 @@ class ManualAlarm(alarm.AlarmControlPanel, RestoreEntity):
async def async_added_to_hass(self):
"""Run when entity about to be added to hass."""
await super().async_added_to_hass()
state = await self.async_get_last_state()
if state:
self._state = state.state
self._state_ts = state.last_updated
if state.state == STATE_ALARM_PENDING and \
hasattr(state, 'attributes') and \
state.attributes['pre_pending_state']:
# If in pending state, we return to the pre_pending_state
self._state = state.attributes['pre_pending_state']
self._state_ts = dt_util.utcnow()
else:
self._state = state.state
self._state_ts = state.last_updated

View File

@@ -14,7 +14,7 @@ from homeassistant.const import (
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.discovery import async_load_platform
REQUIREMENTS = ['aioasuswrt==1.1.13']
REQUIREMENTS = ['aioasuswrt==1.1.15']
_LOGGER = logging.getLogger(__name__)

View File

@@ -423,9 +423,7 @@ class XiaomiButton(XiaomiBinarySensor):
})
self._last_action = click_type
if value in ['long_click_press', 'long_click_release']:
return True
return False
return True
class XiaomiCube(XiaomiBinarySensor):

View File

@@ -88,7 +88,7 @@ async def websocket_get_entity(hass, connection, msg):
@async_response
async def websocket_update_entity(hass, connection, msg):
"""Handle get camera thumbnail websocket command.
"""Handle update entity websocket command.
Async friendly.
"""
@@ -104,8 +104,12 @@ async def websocket_update_entity(hass, connection, msg):
if 'name' in msg:
changes['name'] = msg['name']
if 'new_entity_id' in msg:
if 'new_entity_id' in msg and msg['new_entity_id'] != msg['entity_id']:
changes['new_entity_id'] = msg['new_entity_id']
if hass.states.get(msg['new_entity_id']) is not None:
connection.send_message(websocket_api.error_message(
msg['id'], 'invalid_info', 'Entity is already registered'))
return
try:
if changes:

View File

@@ -316,14 +316,19 @@ async def async_handle_waypoints_message(hass, context, message):
@HANDLERS.register('encrypted')
async def async_handle_encrypted_message(hass, context, message):
"""Handle an encrypted message."""
plaintext_payload = _decrypt_payload(context.secret, message['topic'],
if 'topic' not in message and isinstance(context.secret, dict):
_LOGGER.error("You cannot set per topic secrets when using HTTP")
return
plaintext_payload = _decrypt_payload(context.secret, message.get('topic'),
message['data'])
if plaintext_payload is None:
return
decrypted = json.loads(plaintext_payload)
decrypted['topic'] = message['topic']
if 'topic' in message and 'topic' not in decrypted:
decrypted['topic'] = message['topic']
await async_handle_message(hass, context, decrypted)

View File

@@ -24,7 +24,7 @@ from homeassistant.core import callback
from homeassistant.helpers.translation import async_get_translations
from homeassistant.loader import bind_hass
REQUIREMENTS = ['home-assistant-frontend==20181211.0']
REQUIREMENTS = ['home-assistant-frontend==20181211.1']
DOMAIN = 'frontend'
DEPENDENCIES = ['api', 'websocket_api', 'http', 'system_log',

View File

@@ -42,7 +42,7 @@ class LutronLight(LutronDevice, Light):
def __init__(self, area_name, lutron_device, controller):
"""Initialize the light."""
self._prev_brightness = None
super().__init__(self, area_name, lutron_device, controller)
super().__init__(area_name, lutron_device, controller)
@property
def supported_features(self):
@@ -75,8 +75,7 @@ class LutronLight(LutronDevice, Light):
@property
def device_state_attributes(self):
"""Return the state attributes."""
attr = {}
attr['lutron_integration_id'] = self._lutron_device.id
attr = {'lutron_integration_id': self._lutron_device.id}
return attr
@property

View File

@@ -29,8 +29,9 @@ SERVICE_CLEAR_USERCODE = 'clear_usercode'
POLYCONTROL = 0x10E
DANALOCK_V2_BTZE = 0x2
POLYCONTROL_DANALOCK_V2_BTZE_LOCK = (POLYCONTROL, DANALOCK_V2_BTZE)
WORKAROUND_V2BTZE = 'v2btze'
WORKAROUND_DEVICE_STATE = 'state'
WORKAROUND_V2BTZE = 1
WORKAROUND_DEVICE_STATE = 2
WORKAROUND_TRACK_MESSAGE = 4
DEVICE_MAPPINGS = {
POLYCONTROL_DANALOCK_V2_BTZE_LOCK: WORKAROUND_V2BTZE,
@@ -43,7 +44,7 @@ DEVICE_MAPPINGS = {
# Yale YRD220 (as reported by adrum in PR #17386)
(0x0109, 0x0000): WORKAROUND_DEVICE_STATE,
# Schlage BE469
(0x003B, 0x5044): WORKAROUND_DEVICE_STATE,
(0x003B, 0x5044): WORKAROUND_DEVICE_STATE | WORKAROUND_TRACK_MESSAGE,
# Schlage FE599NX
(0x003B, 0x504C): WORKAROUND_DEVICE_STATE,
}
@@ -51,13 +52,15 @@ DEVICE_MAPPINGS = {
LOCK_NOTIFICATION = {
'1': 'Manual Lock',
'2': 'Manual Unlock',
'3': 'RF Lock',
'4': 'RF Unlock',
'5': 'Keypad Lock',
'6': 'Keypad Unlock',
'11': 'Lock Jammed',
'254': 'Unknown Event'
}
NOTIFICATION_RF_LOCK = '3'
NOTIFICATION_RF_UNLOCK = '4'
LOCK_NOTIFICATION[NOTIFICATION_RF_LOCK] = 'RF Lock'
LOCK_NOTIFICATION[NOTIFICATION_RF_UNLOCK] = 'RF Unlock'
LOCK_ALARM_TYPE = {
'9': 'Deadbolt Jammed',
@@ -66,8 +69,6 @@ LOCK_ALARM_TYPE = {
'19': 'Unlocked with Keypad by user ',
'21': 'Manually Locked ',
'22': 'Manually Unlocked ',
'24': 'Locked by RF',
'25': 'Unlocked by RF',
'27': 'Auto re-lock',
'33': 'User deleted: ',
'112': 'Master code changed or User added: ',
@@ -79,6 +80,10 @@ LOCK_ALARM_TYPE = {
'168': 'Critical Battery Level',
'169': 'Battery too low to operate'
}
ALARM_RF_LOCK = '24'
ALARM_RF_UNLOCK = '25'
LOCK_ALARM_TYPE[ALARM_RF_LOCK] = 'Locked by RF'
LOCK_ALARM_TYPE[ALARM_RF_UNLOCK] = 'Unlocked by RF'
MANUAL_LOCK_ALARM_LEVEL = {
'1': 'by Key Cylinder or Inside thumb turn',
@@ -229,6 +234,8 @@ class ZwaveLock(zwave.ZWaveDeviceEntity, LockDevice):
self._lock_status = None
self._v2btze = None
self._state_workaround = False
self._track_message_workaround = False
self._previous_message = None
# Enable appropriate workaround flags for our device
# Make sure that we have values for the key before converting to int
@@ -237,26 +244,30 @@ class ZwaveLock(zwave.ZWaveDeviceEntity, LockDevice):
specific_sensor_key = (int(self.node.manufacturer_id, 16),
int(self.node.product_id, 16))
if specific_sensor_key in DEVICE_MAPPINGS:
if DEVICE_MAPPINGS[specific_sensor_key] == WORKAROUND_V2BTZE:
workaround = DEVICE_MAPPINGS[specific_sensor_key]
if workaround & WORKAROUND_V2BTZE:
self._v2btze = 1
_LOGGER.debug("Polycontrol Danalock v2 BTZE "
"workaround enabled")
if DEVICE_MAPPINGS[specific_sensor_key] == \
WORKAROUND_DEVICE_STATE:
if workaround & WORKAROUND_DEVICE_STATE:
self._state_workaround = True
_LOGGER.debug(
"Notification device state workaround enabled")
if workaround & WORKAROUND_TRACK_MESSAGE:
self._track_message_workaround = True
_LOGGER.debug("Message tracking workaround enabled")
self.update_properties()
def update_properties(self):
"""Handle data changes for node values."""
self._state = self.values.primary.data
_LOGGER.debug("Lock state set from Bool value and is %s", self._state)
_LOGGER.debug("lock state set to %s", self._state)
if self.values.access_control:
notification_data = self.values.access_control.data
self._notification = LOCK_NOTIFICATION.get(str(notification_data))
if self._state_workaround:
self._state = LOCK_STATUS.get(str(notification_data))
_LOGGER.debug("workaround: lock state set to %s", self._state)
if self._v2btze:
if self.values.v2btze_advanced and \
self.values.v2btze_advanced.data == CONFIG_ADVANCED:
@@ -265,16 +276,37 @@ class ZwaveLock(zwave.ZWaveDeviceEntity, LockDevice):
"Lock state set from Access Control value and is %s, "
"get=%s", str(notification_data), self.state)
if self._track_message_workaround:
this_message = self.node.stats['lastReceivedMessage'][5]
if this_message == zwave.const.COMMAND_CLASS_DOOR_LOCK:
self._state = self.values.primary.data
_LOGGER.debug("set state to %s based on message tracking",
self._state)
if self._previous_message == \
zwave.const.COMMAND_CLASS_DOOR_LOCK:
if self._state:
self._notification = \
LOCK_NOTIFICATION[NOTIFICATION_RF_LOCK]
self._lock_status = \
LOCK_ALARM_TYPE[ALARM_RF_LOCK]
else:
self._notification = \
LOCK_NOTIFICATION[NOTIFICATION_RF_UNLOCK]
self._lock_status = \
LOCK_ALARM_TYPE[ALARM_RF_UNLOCK]
return
self._previous_message = this_message
if not self.values.alarm_type:
return
alarm_type = self.values.alarm_type.data
_LOGGER.debug("Lock alarm_type is %s", str(alarm_type))
if self.values.alarm_level:
alarm_level = self.values.alarm_level.data
else:
alarm_level = None
_LOGGER.debug("Lock alarm_level is %s", str(alarm_level))
if not alarm_type:
return

View File

@@ -60,7 +60,8 @@ CONFIG_SCHEMA = vol.Schema({
ALL_EVENT_TYPES = [
EVENT_STATE_CHANGED, EVENT_LOGBOOK_ENTRY,
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP,
EVENT_ALEXA_SMART_HOME, EVENT_HOMEKIT_CHANGED
EVENT_ALEXA_SMART_HOME, EVENT_HOMEKIT_CHANGED,
EVENT_AUTOMATION_TRIGGERED, EVENT_SCRIPT_STARTED
]
LOG_MESSAGE_SCHEMA = vol.Schema({
@@ -468,6 +469,14 @@ def _exclude_events(events, entities_filter):
domain = event.data.get(ATTR_DOMAIN)
entity_id = event.data.get(ATTR_ENTITY_ID)
elif event.event_type == EVENT_AUTOMATION_TRIGGERED:
domain = 'automation'
entity_id = event.data.get(ATTR_ENTITY_ID)
elif event.event_type == EVENT_SCRIPT_STARTED:
domain = 'script'
entity_id = event.data.get(ATTR_ENTITY_ID)
elif event.event_type == EVENT_ALEXA_SMART_HOME:
domain = 'alexa'

View File

@@ -18,7 +18,7 @@ from .config_flow import CONF_SECRET
DOMAIN = "owntracks"
REQUIREMENTS = ['libnacl==1.6.1']
DEPENDENCIES = ['device_tracker', 'webhook']
DEPENDENCIES = ['webhook']
CONF_MAX_GPS_ACCURACY = 'max_gps_accuracy'
CONF_WAYPOINT_IMPORT = 'waypoints'
@@ -137,15 +137,16 @@ async def handle_webhook(hass, webhook_id, request):
user = headers.get('X-Limit-U')
device = headers.get('X-Limit-D', user)
if user is None:
if user:
topic_base = re.sub('/#$', '', context.mqtt_topic)
message['topic'] = '{}/{}/{}'.format(topic_base, user, device)
elif message['_type'] != 'encrypted':
_LOGGER.warning('No topic or user found in message. If on Android,'
' set a username in Connection -> Identification')
# Keep it as a 200 response so the incorrect packet is discarded
return json_response([])
topic_base = re.sub('/#$', '', context.mqtt_topic)
message['topic'] = '{}/{}/{}'.format(topic_base, user, device)
hass.helpers.dispatcher.async_dispatcher_send(
DOMAIN, hass, context, message)
return json_response([])

View File

@@ -5,6 +5,7 @@ For more details about this component, please refer to the documentation at
https://home-assistant.io/components/tts.amazon_polly/
"""
import logging
import voluptuous as vol
from homeassistant.components.tts import Provider, PLATFORM_SCHEMA
@@ -56,7 +57,7 @@ SUPPORTED_VOICES = [
'Cristiano', 'Ines', # Portuguese, European
'Carmen', # Romanian
'Maxim', 'Tatyana', # Russian
'Enrique', 'Conchita', 'Lucia' # Spanish European
'Enrique', 'Conchita', 'Lucia', # Spanish European
'Mia', # Spanish Mexican
'Miguel', 'Penelope', # Spanish US
'Astrid', # Swedish

View File

@@ -100,6 +100,6 @@ class ZhaEntity(entity.Entity):
'identifiers': {(DOMAIN, ieee)},
'manufacturer': self._endpoint.manufacturer,
'model': self._endpoint.model,
'name': self._device_state_attributes['friendly_name'],
'name': self._device_state_attributes.get('friendly_name', ieee),
'via_hub': (DOMAIN, self.hass.data[DATA_ZHA][DATA_ZHA_BRIDGE_ID]),
}

View File

@@ -2,7 +2,7 @@
"""Constants used by Home Assistant components."""
MAJOR_VERSION = 0
MINOR_VERSION = 84
PATCH_VERSION = '0'
PATCH_VERSION = '3'
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)
REQUIRED_PYTHON_VER = (3, 5, 3)

View File

@@ -297,7 +297,8 @@ class EntityPlatform:
self.domain, self.platform_name, entity.unique_id,
suggested_object_id=suggested_object_id,
config_entry_id=config_entry_id,
device_id=device_id)
device_id=device_id,
known_object_ids=self.entities.keys())
if entry.disabled:
self.logger.info(

View File

@@ -117,7 +117,7 @@ class EntityRegistry:
@callback
def async_get_or_create(self, domain, platform, unique_id, *,
suggested_object_id=None, config_entry_id=None,
device_id=None):
device_id=None, known_object_ids=None):
"""Get entity. Create if it doesn't exist."""
entity_id = self.async_get_entity_id(domain, platform, unique_id)
if entity_id:
@@ -126,7 +126,8 @@ class EntityRegistry:
device_id=device_id)
entity_id = self.async_generate_entity_id(
domain, suggested_object_id or '{}_{}'.format(platform, unique_id))
domain, suggested_object_id or '{}_{}'.format(platform, unique_id),
known_object_ids)
entity = RegistryEntry(
entity_id=entity_id,

View File

@@ -87,7 +87,7 @@ abodepy==0.14.0
afsapi==0.0.4
# homeassistant.components.asuswrt
aioasuswrt==1.1.13
aioasuswrt==1.1.15
# homeassistant.components.device_tracker.automatic
aioautomatic==0.6.5
@@ -493,7 +493,7 @@ hole==0.3.0
holidays==0.9.8
# homeassistant.components.frontend
home-assistant-frontend==20181211.0
home-assistant-frontend==20181211.1
# homeassistant.components.zwave
homeassistant-pyozw==0.1.1

View File

@@ -101,7 +101,7 @@ hdate==0.7.5
holidays==0.9.8
# homeassistant.components.frontend
home-assistant-frontend==20181211.0
home-assistant-frontend==20181211.1
# homeassistant.components.homematicip_cloud
homematicip==0.9.8

View File

@@ -277,6 +277,8 @@ def setup_comp(hass):
"""Initialize components."""
mock_component(hass, 'group')
mock_component(hass, 'zone')
hass.loop.run_until_complete(async_setup_component(
hass, 'device_tracker', {}))
hass.loop.run_until_complete(async_mock_mqtt_component(hass))
hass.states.async_set(

View File

@@ -62,7 +62,7 @@ def test_lock_value_changed(mock_openzwave):
assert device.is_locked
def test_lock_value_changed_workaround(mock_openzwave):
def test_lock_state_workaround(mock_openzwave):
"""Test value changed for Z-Wave lock using notification state."""
node = MockNode(manufacturer_id='0090', product_id='0440')
values = MockEntityValues(
@@ -78,6 +78,50 @@ def test_lock_value_changed_workaround(mock_openzwave):
assert not device.is_locked
def test_track_message_workaround(mock_openzwave):
"""Test value changed for Z-Wave lock by alarm-clearing workaround."""
node = MockNode(manufacturer_id='003B', product_id='5044',
stats={'lastReceivedMessage': [0] * 6})
values = MockEntityValues(
primary=MockValue(data=True, node=node),
access_control=None,
alarm_type=None,
alarm_level=None,
)
# Here we simulate an RF lock. The first zwave.get_device will call
# update properties, simulating the first DoorLock report. We then trigger
# a change, simulating the openzwave automatic refreshing behavior (which
# is enabled for at least the lock that needs this workaround)
node.stats['lastReceivedMessage'][5] = const.COMMAND_CLASS_DOOR_LOCK
device = zwave.get_device(node=node, values=values)
value_changed(values.primary)
assert device.is_locked
assert device.device_state_attributes[zwave.ATTR_NOTIFICATION] == 'RF Lock'
# Simulate a keypad unlock. We trigger a value_changed() which simulates
# the Alarm notification received from the lock. Then, we trigger
# value_changed() to simulate the automatic refreshing behavior.
values.access_control = MockValue(data=6, node=node)
values.alarm_type = MockValue(data=19, node=node)
values.alarm_level = MockValue(data=3, node=node)
node.stats['lastReceivedMessage'][5] = const.COMMAND_CLASS_ALARM
value_changed(values.access_control)
node.stats['lastReceivedMessage'][5] = const.COMMAND_CLASS_DOOR_LOCK
values.primary.data = False
value_changed(values.primary)
assert not device.is_locked
assert device.device_state_attributes[zwave.ATTR_LOCK_STATUS] == \
'Unlocked with Keypad by user 3'
# Again, simulate an RF lock.
device.lock()
node.stats['lastReceivedMessage'][5] = const.COMMAND_CLASS_DOOR_LOCK
value_changed(values.primary)
assert device.is_locked
assert device.device_state_attributes[zwave.ATTR_NOTIFICATION] == 'RF Lock'
def test_v2btze_value_changed(mock_openzwave):
"""Test value changed for v2btze Z-Wave lock."""
node = MockNode(manufacturer_id='010e', product_id='0002')

View File

@@ -265,22 +265,50 @@ class TestComponentLogbook(unittest.TestCase):
def test_exclude_automation_events(self):
"""Test if automation entries can be excluded by entity_id."""
name = 'My Automation Rule'
message = 'has been triggered'
domain = 'automation'
entity_id = 'automation.my_automation_rule'
entity_id2 = 'automation.my_automation_rule_2'
entity_id2 = 'sensor.blu'
eventA = ha.Event(logbook.EVENT_LOGBOOK_ENTRY, {
eventA = ha.Event(logbook.EVENT_AUTOMATION_TRIGGERED, {
logbook.ATTR_NAME: name,
logbook.ATTR_MESSAGE: message,
logbook.ATTR_DOMAIN: domain,
logbook.ATTR_ENTITY_ID: entity_id,
})
eventB = ha.Event(logbook.EVENT_LOGBOOK_ENTRY, {
eventB = ha.Event(logbook.EVENT_AUTOMATION_TRIGGERED, {
logbook.ATTR_NAME: name,
logbook.ATTR_ENTITY_ID: entity_id2,
})
config = logbook.CONFIG_SCHEMA({
ha.DOMAIN: {},
logbook.DOMAIN: {logbook.CONF_EXCLUDE: {
logbook.CONF_ENTITIES: [entity_id, ]}}})
events = logbook._exclude_events(
(ha.Event(EVENT_HOMEASSISTANT_STOP), eventA, eventB),
logbook._generate_filter_from_config(config[logbook.DOMAIN]))
entries = list(logbook.humanify(self.hass, events))
assert 2 == len(entries)
self.assert_entry(
entries[0], name='Home Assistant', message='stopped',
domain=ha.DOMAIN)
self.assert_entry(
entries[1], name=name, domain=domain, entity_id=entity_id2)
def test_exclude_script_events(self):
"""Test if script start can be excluded by entity_id."""
name = 'My Script Rule'
domain = 'script'
entity_id = 'script.my_script'
entity_id2 = 'script.my_script_2'
entity_id2 = 'sensor.blu'
eventA = ha.Event(logbook.EVENT_SCRIPT_STARTED, {
logbook.ATTR_NAME: name,
logbook.ATTR_ENTITY_ID: entity_id,
})
eventB = ha.Event(logbook.EVENT_SCRIPT_STARTED, {
logbook.ATTR_NAME: name,
logbook.ATTR_MESSAGE: message,
logbook.ATTR_DOMAIN: domain,
logbook.ATTR_ENTITY_ID: entity_id2,
})