Change phrases in the logbook component for persons and binary_sensors (#25053)

Persons are now threated the same as device trackers, so the logbook states
"<name> is at <location>" or "<name> is away" instead of "<name> changed to <location|not_home>"

Binary sensors now show phrases that relate to their device_class attribute.
So "Front door is closed" instead of "Front door turned off" or "Hallway PIR detected movement"
instead of "Hallway PIR turned on"
This commit is contained in:
Martijn van Zal authored and Paulus Schoutsen committed 2019-07-10 15:56:41 -07:00
1 parent e51b5e801e
commit ca8118138c
2 files changed
+513 -1

No files matched your search

+54 -1
View File
@@ -486,7 +486,7 @@ def _keep_event(event, entities_filter):
def _entry_message_from_state(domain, state):
"""Convert a state to a message for the logbook."""
# We pass domain in so we don't have to split entity_id again
if domain == 'device_tracker':
if domain in ['device_tracker', 'person']:
if state.state == STATE_NOT_HOME:
return 'is away'
return 'is at {}'.format(state.state)
@@ -496,6 +496,59 @@ def _entry_message_from_state(domain, state):
return 'has risen'
return 'has set'
device_class = state.attributes.get('device_class')
if domain == 'binary_sensor' and device_class:
if device_class == 'battery':
if state.state == STATE_ON:
return "is low"
if state.state == STATE_OFF:
return "is normal"
if device_class == 'connectivity':
if state.state == STATE_ON:
return "is connected"
if state.state == STATE_OFF:
return "is disconnected"
if device_class in ['door', 'garage_door', 'opening', 'window']:
if state.state == STATE_ON:
return "is opened"
if state.state == STATE_OFF:
return "is closed"
if device_class == 'lock':
if state.state == STATE_ON:
return "is unlocked"
if state.state == STATE_OFF:
return "is locked"
if device_class == 'plug':
if state.state == STATE_ON:
return "is plugged in"
if state.state == STATE_OFF:
return "is unplugged"
if device_class == 'presence':
if state.state == STATE_ON:
return "is at home"
if state.state == STATE_OFF:
return "is away"
if device_class == 'safety':
if state.state == STATE_ON:
return "is unsafe"
if state.state == STATE_OFF:
return "is safe"
if (device_class in [
'cold', 'gas', 'heat', 'light', 'moisture', 'motion',
'occupancy', 'power', 'problem', 'smoke', 'sound', 'vibration'
]):
if state.state == STATE_ON:
return "detected {}".format(device_class)
if state.state == STATE_OFF:
return "cleared (no {} detected)".format(device_class)
if state.state == STATE_ON:
# Future: combine groups and its entity entries ?
return "turned on"