Add and use frequency constants (#34113)

This commit is contained in:
springstan 2020-04-12 22:44:31 +02:00 committed by GitHub
parent 00b6409b76
commit 19dd797dfe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 29 additions and 14 deletions

View file

@ -7,6 +7,7 @@ import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import (
CONF_RESOURCES,
FREQUENCY_HERTZ,
POWER_WATT,
TEMP_CELSIUS,
TIME_MINUTES,
@ -49,7 +50,7 @@ SENSOR_TYPES = {
"itemp": ["Internal Temperature", TEMP_CELSIUS, "mdi:thermometer"],
"lastxfer": ["Last Transfer", "", "mdi:transfer"],
"linefail": ["Input Voltage Status", "", "mdi:information-outline"],
"linefreq": ["Line Frequency", "Hz", "mdi:information-outline"],
"linefreq": ["Line Frequency", FREQUENCY_HERTZ, "mdi:information-outline"],
"linev": ["Input Voltage", UNIT_VOLT, "mdi:flash"],
"loadpct": ["Load", UNIT_PERCENTAGE, "mdi:gauge"],
"loadapnt": ["Load Apparent Power", UNIT_PERCENTAGE, "mdi:gauge"],
@ -100,7 +101,7 @@ INFERRED_UNITS = {
" Ampere": "A",
" Volt-Ampere": "VA",
" Watts": POWER_WATT,
" Hz": "Hz",
" Hz": FREQUENCY_HERTZ,
" C": TEMP_CELSIUS,
" Percent Load Capacity": UNIT_PERCENTAGE,
}

View file

@ -5,7 +5,7 @@ from cpuinfo import cpuinfo
import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import CONF_NAME
from homeassistant.const import CONF_NAME, FREQUENCY_GIGAHERTZ
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
@ -42,7 +42,6 @@ class CpuSpeedSensor(Entity):
self._name = name
self._state = None
self.info = None
self._unit_of_measurement = "GHz"
@property
def name(self):
@ -57,7 +56,7 @@ class CpuSpeedSensor(Entity):
@property
def unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self._unit_of_measurement
return FREQUENCY_GIGAHERTZ
@property
def device_state_attributes(self):

View file

@ -13,6 +13,7 @@ from homeassistant.const import (
CONF_PASSWORD,
CONF_USERNAME,
ENERGY_KILO_WATT_HOUR,
FREQUENCY_HERTZ,
POWER_WATT,
UNIT_VOLT,
)
@ -71,7 +72,7 @@ INVERTER_SENSOR_TYPES = {
"inverter_internal_wattage": ("Internal wattage", POWER_WATT, "ppv", "power"),
"inverter_reactive_voltage": ("Reactive voltage", UNIT_VOLT, "vacr", None),
"inverter_inverter_reactive_amperage": ("Reactive amperage", "A", "iacr", None),
"inverter_frequency": ("AC frequency", "Hz", "fac", None),
"inverter_frequency": ("AC frequency", FREQUENCY_HERTZ, "fac", None),
"inverter_current_wattage": ("Output power", POWER_WATT, "pac", "power"),
"inverter_current_reactive_wattage": (
"Reactive wattage",

View file

@ -7,6 +7,7 @@ from homeassistant.const import (
DEVICE_CLASS_POWER,
DEVICE_CLASS_TEMPERATURE,
ENERGY_WATT_HOUR,
FREQUENCY_HERTZ,
POWER_WATT,
SPEED_KILOMETERS_PER_HOUR,
TEMP_CELSIUS,
@ -58,7 +59,7 @@ HM_UNIT_HA_CAST = {
"WIND_DIRECTION_RANGE": UNIT_DEGREE,
"SUNSHINEDURATION": "#",
"AIR_PRESSURE": "hPa",
"FREQUENCY": "Hz",
"FREQUENCY": FREQUENCY_HERTZ,
"VALUE": "#",
}

View file

@ -5,6 +5,7 @@ from typing import Callable
from homeassistant.components.sensor import DOMAIN
from homeassistant.const import (
CONCENTRATION_PARTS_PER_MILLION,
FREQUENCY_HERTZ,
LENGTH_CENTIMETERS,
LENGTH_KILOMETERS,
LENGTH_METERS,
@ -110,7 +111,7 @@ UOM_FRIENDLY_NAME = {
"87": "m³/m³",
"88": "Water activity",
"89": "RPM",
"90": "Hz",
"90": FREQUENCY_HERTZ,
"91": f"{UNIT_DEGREE} (Relative to North)",
"92": f"{UNIT_DEGREE} (Relative to South)",
}

View file

@ -3,6 +3,7 @@ from homeassistant.components import mysensors
from homeassistant.components.sensor import DOMAIN
from homeassistant.const import (
ENERGY_KILO_WATT_HOUR,
FREQUENCY_HERTZ,
LENGTH_METERS,
MASS_KILOGRAMS,
POWER_WATT,
@ -36,7 +37,7 @@ SENSORS = {
"V_VOLUME": ["", None],
"V_LEVEL": {
"S_SOUND": ["dB", "mdi:volume-high"],
"S_VIBRATION": ["Hz", None],
"S_VIBRATION": [FREQUENCY_HERTZ, None],
"S_LIGHT_LEVEL": ["lx", "mdi:white-balance-sunny"],
},
"V_VOLTAGE": [UNIT_VOLT, "mdi:flash"],

View file

@ -5,6 +5,7 @@ from homeassistant.components.sensor import (
DEVICE_CLASS_TEMPERATURE,
)
from homeassistant.const import (
FREQUENCY_HERTZ,
POWER_WATT,
TEMP_CELSIUS,
TIME_SECONDS,
@ -159,10 +160,10 @@ SENSOR_TYPES = {
],
"input.voltage": ["Input Voltage", UNIT_VOLT, "mdi:flash", None],
"input.voltage.nominal": ["Nominal Input Voltage", UNIT_VOLT, "mdi:flash", None],
"input.frequency": ["Input Line Frequency", "hz", "mdi:flash", None],
"input.frequency": ["Input Line Frequency", FREQUENCY_HERTZ, "mdi:flash", None],
"input.frequency.nominal": [
"Nominal Input Line Frequency",
"hz",
FREQUENCY_HERTZ,
"mdi:flash",
None,
],
@ -176,8 +177,13 @@ SENSOR_TYPES = {
"output.current.nominal": ["Nominal Output Current", "A", "mdi:flash", None],
"output.voltage": ["Output Voltage", UNIT_VOLT, "mdi:flash", None],
"output.voltage.nominal": ["Nominal Output Voltage", UNIT_VOLT, "mdi:flash", None],
"output.frequency": ["Output Frequency", "hz", "mdi:flash", None],
"output.frequency.nominal": ["Nominal Output Frequency", "hz", "mdi:flash", None],
"output.frequency": ["Output Frequency", FREQUENCY_HERTZ, "mdi:flash", None],
"output.frequency.nominal": [
"Nominal Output Frequency",
FREQUENCY_HERTZ,
"mdi:flash",
None,
],
}
STATE_TYPES = {

View file

@ -13,6 +13,7 @@ from homeassistant.const import (
CONF_IP_ADDRESS,
CONF_NAME,
ENERGY_WATT_HOUR,
FREQUENCY_HERTZ,
POWER_WATT,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
@ -58,7 +59,7 @@ SENSOR_TYPES = {
"current_frequency": [
"gridfrequency",
"Grid Frequency",
"Hz",
FREQUENCY_HERTZ,
"mdi:current-ac",
None,
],

View file

@ -381,6 +381,10 @@ LENGTH_FEET: str = "ft"
LENGTH_YARD: str = "yd"
LENGTH_MILES: str = "mi"
# Frequency units
FREQUENCY_HERTZ = "Hz"
FREQUENCY_GIGAHERTZ = f"G{FREQUENCY_HERTZ}"
# Pressure units
PRESSURE_PA: str = "Pa"
PRESSURE_HPA: str = "hPa"