Centrally define Energy Units (kWh and Wh) (#21719)
* centralize energy units kWh and Wh * lint
This commit is contained in:
parent
c0b859d8da
commit
a99d83390e
19 changed files with 70 additions and 51 deletions
|
@ -1,4 +1,6 @@
|
|||
"""Constants for ebus component."""
|
||||
from homeassistant.const import ENERGY_KILO_WATT_HOUR
|
||||
|
||||
DOMAIN = 'ebusd'
|
||||
|
||||
# SensorTypes:
|
||||
|
@ -67,9 +69,9 @@ SENSOR_TYPES = {
|
|||
'ContinuosHeating':
|
||||
['ContinuosHeating', '°C', 'mdi:weather-snowy', 0],
|
||||
'PowerEnergyConsumptionLastMonth':
|
||||
['PrEnergySumHcLastMonth', 'kWh', 'mdi:flash', 0],
|
||||
['PrEnergySumHcLastMonth', ENERGY_KILO_WATT_HOUR, 'mdi:flash', 0],
|
||||
'PowerEnergyConsumptionThisMonth':
|
||||
['PrEnergySumHcThisMonth', 'kWh', 'mdi:flash', 0]
|
||||
['PrEnergySumHcThisMonth', ENERGY_KILO_WATT_HOUR, 'mdi:flash', 0]
|
||||
},
|
||||
'ehp': {
|
||||
'HWTemperature':
|
||||
|
@ -89,12 +91,12 @@ SENSOR_TYPES = {
|
|||
'Flame':
|
||||
['Flame', None, 'mdi:toggle-switch', 2],
|
||||
'PowerEnergyConsumptionHeatingCircuit':
|
||||
['PrEnergySumHc1', 'kWh', 'mdi:flash', 0],
|
||||
['PrEnergySumHc1', ENERGY_KILO_WATT_HOUR, 'mdi:flash', 0],
|
||||
'PowerEnergyConsumptionHotWaterCircuit':
|
||||
['PrEnergySumHwc1', 'kWh', 'mdi:flash', 0],
|
||||
['PrEnergySumHwc1', ENERGY_KILO_WATT_HOUR, 'mdi:flash', 0],
|
||||
'RoomThermostat':
|
||||
['DCRoomthermostat', None, 'mdi:toggle-switch', 2],
|
||||
'HeatingPartLoad':
|
||||
['PartloadHcKW', 'kWh', 'mdi:flash', 0]
|
||||
['PartloadHcKW', ENERGY_KILO_WATT_HOUR, 'mdi:flash', 0]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@ from homeassistant.components.fritzbox import DOMAIN as FRITZBOX_DOMAIN
|
|||
from homeassistant.components.fritzbox import (
|
||||
ATTR_STATE_DEVICE_LOCKED, ATTR_STATE_LOCKED)
|
||||
from homeassistant.components.switch import SwitchDevice
|
||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
|
||||
from homeassistant.const import (ATTR_TEMPERATURE, TEMP_CELSIUS,
|
||||
ENERGY_KILO_WATT_HOUR)
|
||||
|
||||
DEPENDENCIES = ['fritzbox']
|
||||
|
||||
|
@ -15,7 +16,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||
|
||||
ATTR_TOTAL_CONSUMPTION = 'total_consumption'
|
||||
ATTR_TOTAL_CONSUMPTION_UNIT = 'total_consumption_unit'
|
||||
ATTR_TOTAL_CONSUMPTION_UNIT_VALUE = 'kWh'
|
||||
ATTR_TOTAL_CONSUMPTION_UNIT_VALUE = ENERGY_KILO_WATT_HOUR
|
||||
|
||||
ATTR_TEMPERATURE_UNIT = 'temperature_unit'
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import logging
|
||||
|
||||
from homeassistant.components.homematic import ATTR_DISCOVER_DEVICES, HMDevice
|
||||
from homeassistant.const import STATE_UNKNOWN, POWER_WATT
|
||||
from homeassistant.const import STATE_UNKNOWN, POWER_WATT, ENERGY_WATT_HOUR
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -27,7 +27,7 @@ HM_UNIT_HA_CAST = {
|
|||
'POWER': POWER_WATT,
|
||||
'CURRENT': 'mA',
|
||||
'VOLTAGE': 'V',
|
||||
'ENERGY_COUNTER': 'Wh',
|
||||
'ENERGY_COUNTER': ENERGY_WATT_HOUR,
|
||||
'GAS_POWER': 'm3',
|
||||
'GAS_ENERGY_COUNTER': 'm3',
|
||||
'LUX': 'lx',
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
"""Support for monitoring juicenet/juicepoint/juicebox based EVSE sensors."""
|
||||
import logging
|
||||
|
||||
from homeassistant.const import TEMP_CELSIUS, POWER_WATT
|
||||
from homeassistant.const import TEMP_CELSIUS, POWER_WATT, ENERGY_WATT_HOUR
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.components.juicenet import JuicenetDevice, DOMAIN
|
||||
|
||||
|
@ -16,7 +16,7 @@ SENSOR_TYPES = {
|
|||
'amps': ['Amps', 'A'],
|
||||
'watts': ['Watts', POWER_WATT],
|
||||
'charge_time': ['Charge time', 's'],
|
||||
'energy_added': ['Energy added', 'Wh']
|
||||
'energy_added': ['Energy added', ENERGY_WATT_HOUR]
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
"""Support for MySensors sensors."""
|
||||
from homeassistant.components import mysensors
|
||||
from homeassistant.components.sensor import DOMAIN
|
||||
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT, POWER_WATT
|
||||
from homeassistant.const import (TEMP_CELSIUS, TEMP_FAHRENHEIT, POWER_WATT,
|
||||
ENERGY_KILO_WATT_HOUR)
|
||||
|
||||
SENSORS = {
|
||||
'V_TEMP': [None, 'mdi:thermometer'],
|
||||
|
@ -13,7 +14,7 @@ SENSORS = {
|
|||
'V_DISTANCE': ['m', 'mdi:ruler'],
|
||||
'V_IMPEDANCE': ['ohm', None],
|
||||
'V_WATT': [POWER_WATT, None],
|
||||
'V_KWH': ['kWh', None],
|
||||
'V_KWH': [ENERGY_KILO_WATT_HOUR, None],
|
||||
'V_FLOW': ['m', None],
|
||||
'V_VOLUME': ['m³', None],
|
||||
'V_VOLTAGE': ['V', 'mdi:flash'],
|
||||
|
|
|
@ -3,7 +3,7 @@ from datetime import timedelta
|
|||
import logging
|
||||
|
||||
from homeassistant.components.sense import SENSE_DATA
|
||||
from homeassistant.const import POWER_WATT
|
||||
from homeassistant.const import POWER_WATT, ENERGY_KILO_WATT_HOUR
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
|
||||
|
@ -91,7 +91,7 @@ class Sense(Entity):
|
|||
if sensor_type == ACTIVE_TYPE:
|
||||
self._unit_of_measurement = POWER_WATT
|
||||
else:
|
||||
self._unit_of_measurement = 'kWh'
|
||||
self._unit_of_measurement = ENERGY_KILO_WATT_HOUR
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -10,7 +10,8 @@ import requests
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import CONF_CURRENCY, POWER_WATT
|
||||
from homeassistant.const import (CONF_CURRENCY, POWER_WATT,
|
||||
ENERGY_KILO_WATT_HOUR)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
|
@ -35,7 +36,7 @@ DEFAULT_UTC_OFFSET = '0'
|
|||
|
||||
SENSOR_TYPES = {
|
||||
CONF_INSTANT: ['Energy Usage', POWER_WATT],
|
||||
CONF_AMOUNT: ['Energy Consumed', 'kWh'],
|
||||
CONF_AMOUNT: ['Energy Consumed', ENERGY_KILO_WATT_HOUR],
|
||||
CONF_BUDGET: ['Energy Budget', None],
|
||||
CONF_COST: ['Energy Cost', None],
|
||||
CONF_CURRENT_VALUES: ['Per-Device Usage', POWER_WATT]
|
||||
|
|
|
@ -14,7 +14,7 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import (
|
||||
CONF_USERNAME, CONF_PASSWORD,
|
||||
CONF_USERNAME, CONF_PASSWORD, ENERGY_KILO_WATT_HOUR,
|
||||
CONF_NAME, CONF_MONITORED_VARIABLES, TEMP_CELSIUS)
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
|
@ -24,7 +24,7 @@ REQUIREMENTS = ['pyhydroquebec==2.2.2']
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
KILOWATT_HOUR = 'kWh' # type: str
|
||||
KILOWATT_HOUR = ENERGY_KILO_WATT_HOUR
|
||||
PRICE = 'CAD' # type: str
|
||||
DAYS = 'days' # type: str
|
||||
CONF_CONTRACT = 'contract' # type: str
|
||||
|
|
|
@ -10,7 +10,8 @@ from datetime import timedelta
|
|||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD, CONF_TIMEOUT
|
||||
from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD, CONF_TIMEOUT,
|
||||
ENERGY_KILO_WATT_HOUR)
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
|
@ -71,7 +72,7 @@ class LinkySensor(Entity):
|
|||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
return 'kWh'
|
||||
return ENERGY_KILO_WATT_HOUR
|
||||
|
||||
@Throttle(SCAN_INTERVAL)
|
||||
def update(self):
|
||||
|
|
|
@ -11,7 +11,8 @@ import requests.exceptions
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import (CONF_API_KEY, POWER_WATT)
|
||||
from homeassistant.const import (CONF_API_KEY, POWER_WATT,
|
||||
ENERGY_KILO_WATT_HOUR)
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -150,7 +151,7 @@ class NeurioEnergy(Entity):
|
|||
if sensor_type == ACTIVE_TYPE:
|
||||
self._unit_of_measurement = POWER_WATT
|
||||
elif sensor_type == DAILY_TYPE:
|
||||
self._unit_of_measurement = 'kWh'
|
||||
self._unit_of_measurement = ENERGY_KILO_WATT_HOUR
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -11,8 +11,9 @@ import voluptuous as vol
|
|||
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import TEMP_CELSIUS, CONF_HOST
|
||||
from homeassistant.const import CONF_MONITORED_VARIABLES
|
||||
from homeassistant.const import (
|
||||
TEMP_CELSIUS, CONF_HOST, ENERGY_KILO_WATT_HOUR,
|
||||
CONF_MONITORED_VARIABLES)
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
||||
REQUIREMENTS = ['openevsewifi==0.4']
|
||||
|
@ -25,8 +26,8 @@ SENSOR_TYPES = {
|
|||
'ambient_temp': ['Ambient Temperature', TEMP_CELSIUS],
|
||||
'ir_temp': ['IR Temperature', TEMP_CELSIUS],
|
||||
'rtc_temp': ['RTC Temperature', TEMP_CELSIUS],
|
||||
'usage_session': ['Usage this Session', 'kWh'],
|
||||
'usage_total': ['Total Usage', 'kWh']
|
||||
'usage_session': ['Usage this Session', ENERGY_KILO_WATT_HOUR],
|
||||
'usage_total': ['Total Usage', ENERGY_KILO_WATT_HOUR]
|
||||
}
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
|
|
|
@ -12,7 +12,8 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import (
|
||||
CONF_API_KEY, CONF_MONITORED_CONDITIONS, CONF_NAME, POWER_WATT)
|
||||
CONF_API_KEY, CONF_MONITORED_CONDITIONS, CONF_NAME, POWER_WATT,
|
||||
ENERGY_WATT_HOUR)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
|
@ -28,16 +29,16 @@ SCAN_INTERVAL = timedelta(minutes=10)
|
|||
# Supported sensor types:
|
||||
# Key: ['json_key', 'name', unit, icon]
|
||||
SENSOR_TYPES = {
|
||||
'lifetime_energy': ['lifeTimeData', "Lifetime energy", 'Wh',
|
||||
'mdi:solar-power'],
|
||||
'energy_this_year': ['lastYearData', "Energy this year", 'Wh',
|
||||
'mdi:solar-power'],
|
||||
'energy_this_month': ['lastMonthData', "Energy this month", 'Wh',
|
||||
'mdi:solar-power'],
|
||||
'energy_today': ['lastDayData', "Energy today", 'Wh',
|
||||
'mdi:solar-power'],
|
||||
'current_power': ['currentPower', "Current Power", POWER_WATT,
|
||||
'mdi:solar-power']
|
||||
'lifetime_energy': ['lifeTimeData', "Lifetime energy",
|
||||
ENERGY_WATT_HOUR, 'mdi:solar-power'],
|
||||
'energy_this_year': ['lastYearData', "Energy this year",
|
||||
ENERGY_WATT_HOUR, 'mdi:solar-power'],
|
||||
'energy_this_month': ['lastMonthData', "Energy this month",
|
||||
ENERGY_WATT_HOUR, 'mdi:solar-power'],
|
||||
'energy_today': ['lastDayData', "Energy today",
|
||||
ENERGY_WATT_HOUR, 'mdi:solar-power'],
|
||||
'current_power': ['currentPower', "Current Power",
|
||||
POWER_WATT, 'mdi:solar-power']
|
||||
}
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
|
|
|
@ -12,7 +12,7 @@ from requests.exceptions import (
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.const import (
|
||||
CONF_NAME, CONF_PASSWORD,
|
||||
CONF_NAME, CONF_PASSWORD, ENERGY_KILO_WATT_HOUR,
|
||||
CONF_USERNAME, CONF_ID)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.util import Throttle
|
||||
|
@ -27,7 +27,7 @@ ATTRIBUTION = "Powered by SRP Energy"
|
|||
|
||||
DEFAULT_NAME = 'SRP Energy'
|
||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=1440)
|
||||
ENERGY_KWH = 'kWh'
|
||||
ENERGY_KWH = ENERGY_KILO_WATT_HOUR
|
||||
|
||||
ATTR_READING_COST = "reading_cost"
|
||||
ATTR_READING_TIME = 'datetime'
|
||||
|
|
|
@ -11,7 +11,8 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import (
|
||||
CONF_HOST, CONF_NAME, CONF_PORT, CONF_MONITORED_CONDITIONS, POWER_WATT)
|
||||
CONF_HOST, CONF_NAME, CONF_PORT, CONF_MONITORED_CONDITIONS, POWER_WATT,
|
||||
ENERGY_WATT_HOUR)
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -32,7 +33,7 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=1)
|
|||
|
||||
SENSOR_TYPES = {
|
||||
'average': ['Average', POWER_WATT, 'mdi:power-off'],
|
||||
'consumption': ['Consumption', 'Wh', 'mdi:power-plug'],
|
||||
'consumption': ['Consumption', ENERGY_WATT_HOUR, 'mdi:power-plug'],
|
||||
'max': ['Max', POWER_WATT, 'mdi:arrow-up'],
|
||||
'min': ['Min', POWER_WATT, 'mdi:arrow-down'],
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ from datetime import timedelta
|
|||
|
||||
from homeassistant.components.smappee import DATA_SMAPPEE
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.const import POWER_WATT
|
||||
from homeassistant.const import POWER_WATT, ENERGY_KILO_WATT_HOUR
|
||||
|
||||
DEPENDENCIES = ['smappee']
|
||||
|
||||
|
@ -24,11 +24,14 @@ SENSOR_TYPES = {
|
|||
'active_cosfi':
|
||||
['Power Factor', 'mdi:gauge', 'local', '%', 'active_cosfi'],
|
||||
'alwayson_today':
|
||||
['Always On Today', 'mdi:gauge', 'remote', 'kWh', 'alwaysOn'],
|
||||
['Always On Today', 'mdi:gauge', 'remote', ENERGY_KILO_WATT_HOUR,
|
||||
'alwaysOn'],
|
||||
'solar_today':
|
||||
['Solar Today', 'mdi:white-balance-sunny', 'remote', 'kWh', 'solar'],
|
||||
['Solar Today', 'mdi:white-balance-sunny', 'remote',
|
||||
ENERGY_KILO_WATT_HOUR, 'solar'],
|
||||
'power_today':
|
||||
['Power Today', 'mdi:power-plug', 'remote', 'kWh', 'consumption'],
|
||||
['Power Today', 'mdi:power-plug', 'remote', ENERGY_KILO_WATT_HOUR,
|
||||
'consumption'],
|
||||
'water_sensor_1':
|
||||
['Water Sensor 1', 'mdi:water', 'water', 'm3', 'value1'],
|
||||
'water_sensor_2':
|
||||
|
|
|
@ -5,7 +5,7 @@ from typing import Optional, Sequence
|
|||
from homeassistant.const import (
|
||||
DEVICE_CLASS_BATTERY, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_ILLUMINANCE,
|
||||
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TIMESTAMP, MASS_KILOGRAMS,
|
||||
POWER_WATT, TEMP_CELSIUS, TEMP_FAHRENHEIT)
|
||||
ENERGY_KILO_WATT_HOUR, POWER_WATT, TEMP_CELSIUS, TEMP_FAHRENHEIT)
|
||||
|
||||
from . import SmartThingsEntity
|
||||
from .const import DATA_BROKERS, DOMAIN
|
||||
|
@ -54,7 +54,7 @@ CAPABILITY_TO_SENSORS = {
|
|||
Map('fineDustLevel', "Fine Dust Level", None, None),
|
||||
Map('dustLevel', "Dust Level", None, None)],
|
||||
'energyMeter': [
|
||||
Map('energy', "Energy Meter", 'kWh', None)],
|
||||
Map('energy', "Energy Meter", ENERGY_KILO_WATT_HOUR, None)],
|
||||
'equivalentCarbonDioxideMeasurement': [
|
||||
Map('equivalentCarbonDioxideMeasurement',
|
||||
'Equivalent Carbon Dioxide Measurement', 'ppm', None)],
|
||||
|
|
|
@ -12,7 +12,7 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.components.switch import (SwitchDevice, PLATFORM_SCHEMA)
|
||||
from homeassistant.const import (
|
||||
CONF_HOST, CONF_PASSWORD, CONF_USERNAME, POWER_WATT)
|
||||
CONF_HOST, CONF_PASSWORD, CONF_USERNAME, POWER_WATT, ENERGY_KILO_WATT_HOUR)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.const import TEMP_CELSIUS, ATTR_TEMPERATURE
|
||||
|
||||
|
@ -29,7 +29,7 @@ ATTR_CURRENT_CONSUMPTION_UNIT_VALUE = POWER_WATT
|
|||
|
||||
ATTR_TOTAL_CONSUMPTION = 'total_consumption'
|
||||
ATTR_TOTAL_CONSUMPTION_UNIT = 'total_consumption_unit'
|
||||
ATTR_TOTAL_CONSUMPTION_UNIT_VALUE = 'kWh'
|
||||
ATTR_TOTAL_CONSUMPTION_UNIT_VALUE = ENERGY_KILO_WATT_HOUR
|
||||
|
||||
ATTR_TEMPERATURE_UNIT = 'temperature_unit'
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
"""Constants for the Toon integration."""
|
||||
from homeassistant.const import ENERGY_KILO_WATT_HOUR
|
||||
|
||||
DOMAIN = 'toon'
|
||||
|
||||
DATA_TOON = 'toon'
|
||||
|
@ -15,7 +17,7 @@ DEFAULT_MIN_TEMP = 6.0
|
|||
|
||||
CURRENCY_EUR = 'EUR'
|
||||
POWER_WATT = 'W'
|
||||
POWER_KWH = 'kWh'
|
||||
POWER_KWH = ENERGY_KILO_WATT_HOUR
|
||||
RATIO_PERCENT = '%'
|
||||
VOLUME_CM3 = 'CM3'
|
||||
VOLUME_M3 = 'M3'
|
||||
|
|
|
@ -325,6 +325,10 @@ ATTR_TEMPERATURE = 'temperature'
|
|||
# Power units
|
||||
POWER_WATT = 'W'
|
||||
|
||||
# Energy units
|
||||
ENERGY_KILO_WATT_HOUR = 'kWh'
|
||||
ENERGY_WATT_HOUR = 'Wh'
|
||||
|
||||
# Temperature units
|
||||
TEMP_CELSIUS = '°C'
|
||||
TEMP_FAHRENHEIT = '°F'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue