Minor tweaks for sensor device automations (#27829)

* Minor tweaks for sensor device automations

* Change unit_of_measurement to suffix in extra_fields

* Address review comment
This commit is contained in:
Erik Montnemery 2019-10-22 20:40:07 +02:00 committed by Paulus Schoutsen
parent 04dbe5bc84
commit 4700d647b0
3 changed files with 22 additions and 30 deletions

View File

@ -11,7 +11,6 @@ from homeassistant.const import (
CONF_ENTITY_ID, CONF_ENTITY_ID,
CONF_FOR, CONF_FOR,
CONF_TYPE, CONF_TYPE,
CONF_UNIT_OF_MEASUREMENT,
DEVICE_CLASS_BATTERY, DEVICE_CLASS_BATTERY,
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_ILLUMINANCE,
@ -73,11 +72,6 @@ TRIGGER_SCHEMA = vol.All(
), ),
vol.Optional(CONF_BELOW): vol.Any(vol.Coerce(float)), vol.Optional(CONF_BELOW): vol.Any(vol.Coerce(float)),
vol.Optional(CONF_ABOVE): vol.Any(vol.Coerce(float)), vol.Optional(CONF_ABOVE): vol.Any(vol.Coerce(float)),
vol.Optional(CONF_FOR): vol.Any(
vol.All(cv.time_period, cv.positive_timedelta),
cv.template,
cv.template_complex,
),
vol.Optional(CONF_FOR): cv.positive_time_period_dict, vol.Optional(CONF_FOR): cv.positive_time_period_dict,
} }
), ),
@ -159,12 +153,10 @@ async def async_get_trigger_capabilities(hass, config):
"extra_fields": vol.Schema( "extra_fields": vol.Schema(
{ {
vol.Optional( vol.Optional(
CONF_ABOVE, CONF_ABOVE, description={"suffix": unit_of_measurement}
description={CONF_UNIT_OF_MEASUREMENT: unit_of_measurement},
): vol.Coerce(float), ): vol.Coerce(float),
vol.Optional( vol.Optional(
CONF_BELOW, CONF_BELOW, description={"suffix": unit_of_measurement}
description={CONF_UNIT_OF_MEASUREMENT: unit_of_measurement},
): vol.Coerce(float), ): vol.Coerce(float),
vol.Optional(CONF_FOR): cv.positive_time_period_dict, vol.Optional(CONF_FOR): cv.positive_time_period_dict,
} }

View File

@ -1,26 +1,26 @@
{ {
"device_automation": { "device_automation": {
"condition_type": { "condition_type": {
"is_battery_level": "{entity_name} battery level", "is_battery_level": "Current {entity_name} battery level",
"is_humidity": "{entity_name} humidity", "is_humidity": "Current {entity_name} humidity",
"is_illuminance": "{entity_name} illuminance", "is_illuminance": "Current {entity_name} illuminance",
"is_power": "{entity_name} power", "is_power": "Current {entity_name} power",
"is_pressure": "{entity_name} pressure", "is_pressure": "Current {entity_name} pressure",
"is_signal_strength": "{entity_name} signal strength", "is_signal_strength": "Current {entity_name} signal strength",
"is_temperature": "{entity_name} temperature", "is_temperature": "Current {entity_name} temperature",
"is_timestamp": "{entity_name} timestamp", "is_timestamp": "Current {entity_name} timestamp",
"is_value": "{entity_name} value" "is_value": "Current {entity_name} value"
}, },
"trigger_type": { "trigger_type": {
"battery_level": "{entity_name} battery level", "battery_level": "{entity_name} battery level changes",
"humidity": "{entity_name} humidity", "humidity": "{entity_name} humidity changes",
"illuminance": "{entity_name} illuminance", "illuminance": "{entity_name} illuminance changes",
"power": "{entity_name} power", "power": "{entity_name} power changes",
"pressure": "{entity_name} pressure", "pressure": "{entity_name} pressure changes",
"signal_strength": "{entity_name} signal strength", "signal_strength": "{entity_name} signal strength changes",
"temperature": "{entity_name} temperature", "temperature": "{entity_name} temperature changes",
"timestamp": "{entity_name} timestamp", "timestamp": "{entity_name} timestamp changes",
"value": "{entity_name} value" "value": "{entity_name} value changes"
} }
} }
} }

View File

@ -101,13 +101,13 @@ async def test_get_trigger_capabilities(hass, device_reg, entity_reg):
expected_capabilities = { expected_capabilities = {
"extra_fields": [ "extra_fields": [
{ {
"description": {"unit_of_measurement": "%"}, "description": {"suffix": "%"},
"name": "above", "name": "above",
"optional": True, "optional": True,
"type": "float", "type": "float",
}, },
{ {
"description": {"unit_of_measurement": "%"}, "description": {"suffix": "%"},
"name": "below", "name": "below",
"optional": True, "optional": True,
"type": "float", "type": "float",