From 4f1a28d46013e3d504b1379275a3c6bd28e43bb1 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Tue, 12 Nov 2019 19:04:39 +0100 Subject: [PATCH] Adjust some units (#852) * Adjust some units Fixes https://github.com/esphome/issues/issues/843 * Lint --- esphome/components/atm90e32/sensor.py | 7 ++++--- esphome/components/pzemac/sensor.py | 4 ++-- esphome/components/tx20/sensor.py | 4 ++-- esphome/const.py | 4 +++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/esphome/components/atm90e32/sensor.py b/esphome/components/atm90e32/sensor.py index 030ff90a77..a5d11bbb75 100644 --- a/esphome/components/atm90e32/sensor.py +++ b/esphome/components/atm90e32/sensor.py @@ -4,7 +4,7 @@ from esphome.components import sensor, spi from esphome.const import \ CONF_ID, CONF_VOLTAGE, CONF_CURRENT, CONF_POWER, CONF_POWER_FACTOR, CONF_FREQUENCY, \ ICON_FLASH, ICON_LIGHTBULB, ICON_CURRENT_AC, ICON_THERMOMETER, \ - UNIT_HZ, UNIT_VOLT, UNIT_AMPERE, UNIT_WATT, UNIT_EMPTY, UNIT_CELSIUS + UNIT_HERTZ, UNIT_VOLT, UNIT_AMPERE, UNIT_WATT, UNIT_EMPTY, UNIT_CELSIUS, UNIT_VOLT_AMPS_REACTIVE CONF_PHASE_A = 'phase_a' CONF_PHASE_B = 'phase_b' @@ -33,7 +33,8 @@ ATM90E32_PHASE_SCHEMA = cv.Schema({ cv.Optional(CONF_VOLTAGE): sensor.sensor_schema(UNIT_VOLT, ICON_FLASH, 2), cv.Optional(CONF_CURRENT): sensor.sensor_schema(UNIT_AMPERE, ICON_CURRENT_AC, 2), cv.Optional(CONF_POWER): sensor.sensor_schema(UNIT_WATT, ICON_FLASH, 2), - cv.Optional(CONF_REACTIVE_POWER): sensor.sensor_schema(UNIT_EMPTY, ICON_LIGHTBULB, 2), + cv.Optional(CONF_REACTIVE_POWER): sensor.sensor_schema(UNIT_VOLT_AMPS_REACTIVE, + ICON_LIGHTBULB, 2), cv.Optional(CONF_POWER_FACTOR): sensor.sensor_schema(UNIT_EMPTY, ICON_FLASH, 2), cv.Optional(CONF_GAIN_VOLTAGE, default=41820): cv.uint16_t, cv.Optional(CONF_GAIN_CT, default=25498): cv.uint16_t, @@ -44,7 +45,7 @@ CONFIG_SCHEMA = cv.Schema({ cv.Optional(CONF_PHASE_A): ATM90E32_PHASE_SCHEMA, cv.Optional(CONF_PHASE_B): ATM90E32_PHASE_SCHEMA, cv.Optional(CONF_PHASE_C): ATM90E32_PHASE_SCHEMA, - cv.Optional(CONF_FREQUENCY): sensor.sensor_schema(UNIT_HZ, ICON_CURRENT_AC, 1), + cv.Optional(CONF_FREQUENCY): sensor.sensor_schema(UNIT_HERTZ, ICON_CURRENT_AC, 1), cv.Optional(CONF_CHIP_TEMPERATURE): sensor.sensor_schema(UNIT_CELSIUS, ICON_THERMOMETER, 1), cv.Required(CONF_LINE_FREQUENCY): cv.enum(LINE_FREQS, upper=True), cv.Optional(CONF_GAIN_PGA, default='2X'): cv.enum(PGA_GAINS, upper=True), diff --git a/esphome/components/pzemac/sensor.py b/esphome/components/pzemac/sensor.py index 35d8069767..54eb01e085 100644 --- a/esphome/components/pzemac/sensor.py +++ b/esphome/components/pzemac/sensor.py @@ -3,7 +3,7 @@ import esphome.config_validation as cv from esphome.components import sensor, modbus from esphome.const import CONF_CURRENT, CONF_ID, CONF_POWER, CONF_VOLTAGE, \ CONF_FREQUENCY, UNIT_VOLT, ICON_FLASH, UNIT_AMPERE, UNIT_WATT, UNIT_EMPTY, \ - ICON_POWER, CONF_POWER_FACTOR, ICON_CURRENT_AC + ICON_POWER, CONF_POWER_FACTOR, ICON_CURRENT_AC, UNIT_HERTZ AUTO_LOAD = ['modbus'] @@ -15,7 +15,7 @@ CONFIG_SCHEMA = cv.Schema({ cv.Optional(CONF_VOLTAGE): sensor.sensor_schema(UNIT_VOLT, ICON_FLASH, 1), cv.Optional(CONF_CURRENT): sensor.sensor_schema(UNIT_AMPERE, ICON_CURRENT_AC, 3), cv.Optional(CONF_POWER): sensor.sensor_schema(UNIT_WATT, ICON_POWER, 1), - cv.Optional(CONF_FREQUENCY): sensor.sensor_schema(UNIT_EMPTY, ICON_CURRENT_AC, 1), + cv.Optional(CONF_FREQUENCY): sensor.sensor_schema(UNIT_HERTZ, ICON_CURRENT_AC, 1), cv.Optional(CONF_POWER_FACTOR): sensor.sensor_schema(UNIT_EMPTY, ICON_FLASH, 2), }).extend(cv.polling_component_schema('60s')).extend(modbus.modbus_device_schema(0x01)) diff --git a/esphome/components/tx20/sensor.py b/esphome/components/tx20/sensor.py index daa6677196..3547cdf50c 100644 --- a/esphome/components/tx20/sensor.py +++ b/esphome/components/tx20/sensor.py @@ -4,7 +4,7 @@ from esphome import pins from esphome.components import sensor from esphome.const import CONF_ID, CONF_WIND_SPEED, CONF_PIN, \ CONF_WIND_DIRECTION_DEGREES, UNIT_KILOMETER_PER_HOUR, \ - UNIT_EMPTY, ICON_WEATHER_WINDY, ICON_SIGN_DIRECTION + ICON_WEATHER_WINDY, ICON_SIGN_DIRECTION, UNIT_DEGREES tx20_ns = cg.esphome_ns.namespace('tx20') Tx20Component = tx20_ns.class_('Tx20Component', cg.Component) @@ -14,7 +14,7 @@ CONFIG_SCHEMA = cv.Schema({ cv.Optional(CONF_WIND_SPEED): sensor.sensor_schema(UNIT_KILOMETER_PER_HOUR, ICON_WEATHER_WINDY, 1), cv.Optional(CONF_WIND_DIRECTION_DEGREES): - sensor.sensor_schema(UNIT_EMPTY, ICON_SIGN_DIRECTION, 1), + sensor.sensor_schema(UNIT_DEGREES, ICON_SIGN_DIRECTION, 1), cv.Required(CONF_PIN): cv.All(pins.internal_gpio_input_pin_schema, pins.validate_has_interrupt), }).extend(cv.COMPONENT_SCHEMA) diff --git a/esphome/const.py b/esphome/const.py index 5867666576..829b4738ce 100644 --- a/esphome/const.py +++ b/esphome/const.py @@ -539,7 +539,7 @@ UNIT_DEGREES = u'°' UNIT_EMPTY = '' UNIT_G = 'G' UNIT_HECTOPASCAL = 'hPa' -UNIT_HZ = 'hz' +UNIT_HERTZ = 'hz' UNIT_KELVIN = 'K' UNIT_KILOMETER = 'km' UNIT_KILOMETER_PER_HOUR = 'km/h' @@ -557,6 +557,8 @@ UNIT_PULSES_PER_MINUTE = 'pulses/min' UNIT_SECOND = 's' UNIT_STEPS = 'steps' UNIT_VOLT = 'V' +UNIT_VOLT_AMPS = 'VA' +UNIT_VOLT_AMPS_REACTIVE = 'VAR' UNIT_WATT = 'W' DEVICE_CLASS_CONNECTIVITY = 'connectivity'