-
Notifications
You must be signed in to change notification settings - Fork 59
Closed
Description
Whilst trying to make a battery sensor, I stumbled on some very strange behaviour (I'm doing this in a Jupyter notebook using https://github.com/craigbarratt/hass-pyscript-jupyter).
The script at the top should return an empty list, but instead it returns a list. I explored further and there seems to be something strange about the boolean and operator. Here is what's in my notebook:
import re
state_names = ['sun.sun', 'group.battery_level', 'group.battery_alert', 'input_number.battery_alert_threshold_max']
ignore_sensors = ["sun.sun", "group.battery_level"]
[sensor for sensor in state_names if (re.search(r'_battery(_level)?$', sensor) and (sensor not in ignore_sensors))]['group.battery_alert', 'input_number.battery_alert_threshold_max']
[re.search('battery', sensor) and sensor not in ignore_sensors for sensor in state_names][0, 0, True, True]
type(True and False)<class 'int'>
type(False)<class 'bool'>
type(True)<class 'bool'>
type(True and True)<class 'bool'>
type(True and True)<class 'bool'>
bool(0)False
Metadata
Metadata
Assignees
Labels
No labels