mirror of
https://github.com/fmtr/haco.git
synced 2026-10-26 19:01:51 -04:00
Add UOM and Sensor device class data
This commit is contained in:
parent
328b367bc3
commit
37ff4f17a4
9 changed files with 264 additions and 12 deletions
3
haco/binary_sensor.py
Normal file
3
haco/binary_sensor.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
|
||||
|
||||
|
|
@ -5,7 +5,7 @@ from haco.tools import add_tuya_io
|
|||
|
||||
OPTIONS = ['Default', 'Fries', 'Shrimp', 'Pizza', 'Chicken', 'Fish', 'Steak', 'Cake', 'Bacon', 'Preheat', 'Custom']
|
||||
|
||||
cookbook = Select('Cookbook', options=OPTIONS, icon='mdi:chef-hat')
|
||||
cookbook = Select('Cookbook', options=OPTIONS, icon='chef-hat')
|
||||
|
||||
|
||||
@cookbook.callback()
|
||||
|
|
@ -21,7 +21,7 @@ def tasmota(value: int):
|
|||
time_remaining = Sensor(
|
||||
name='Time Remaining',
|
||||
uom='minutes',
|
||||
icon='mdi:timer',
|
||||
icon='timer',
|
||||
device_class='DURATION'
|
||||
)
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ cooking_time = Number(
|
|||
name='Cooking Time',
|
||||
number_range=range(1, 60),
|
||||
uom='minutes',
|
||||
icon='mdi:timer'
|
||||
icon='timer'
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ cooking_temp_f = Number(
|
|||
number_range=range(170, 399),
|
||||
mode='slider',
|
||||
uom='°F',
|
||||
icon='mdi:temperature-fahrenheit'
|
||||
icon='temperature-fahrenheit'
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ cooking_temp_c = Number(
|
|||
number_range=range(77, 204),
|
||||
mode='slider',
|
||||
uom='°C',
|
||||
icon='mdi:temperature-celsius'
|
||||
icon='temperature-celsius'
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -88,14 +88,14 @@ def tasmota(value: float):
|
|||
|
||||
cook_pause = Switch(
|
||||
name='Cook/Pause',
|
||||
icon='mdi:play-pause'
|
||||
icon='play-pause'
|
||||
)
|
||||
|
||||
add_tuya_io(cook_pause, int, 1, 2)
|
||||
|
||||
power = Switch(
|
||||
name='Power',
|
||||
icon='mdi:power'
|
||||
icon='power'
|
||||
)
|
||||
|
||||
add_tuya_io(power, int, 1, 1)
|
||||
|
|
@ -104,14 +104,14 @@ delay_time = Number(
|
|||
name='Delay Time',
|
||||
number_range=range(0, 720),
|
||||
uom='minutes',
|
||||
icon='mdi:timer-pause'
|
||||
icon='timer-pause'
|
||||
)
|
||||
|
||||
add_tuya_io(delay_time, int, 2, 6)
|
||||
|
||||
status = Sensor(
|
||||
name='Status',
|
||||
icon='mdi:playlist-play',
|
||||
icon='playlist-play',
|
||||
device_class='ENUM'
|
||||
)
|
||||
|
||||
|
|
@ -119,7 +119,7 @@ keep_warm_time = Number(
|
|||
name='Keep Warm Time',
|
||||
number_range=range(0, 120),
|
||||
uom='minutes',
|
||||
icon='mdi:timer-sync'
|
||||
icon='timer-sync'
|
||||
)
|
||||
|
||||
add_tuya_io(keep_warm_time, int, 2, 105)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,16 @@
|
|||
from haco import Sensor
|
||||
|
||||
memory = Sensor('Memory Free', icon='memory', uom=Sensor.UOM.DATA_KILOBYTES, device_class=Sensor.DEVICE_CLASS.DATA_SIZE)
|
||||
|
||||
|
||||
@memory.callback(trigger='Tele#Heap')
|
||||
def tasmota(value: int):
|
||||
return value
|
||||
|
||||
|
||||
from haco import Button, Tasmota
|
||||
|
||||
restart = Button('Restart Tasmota', icon='mdi:restart')
|
||||
restart = Button('Restart Tasmota', icon='restart')
|
||||
|
||||
|
||||
@restart.callback()
|
||||
|
|
|
|||
|
|
@ -36,7 +36,8 @@ class Control:
|
|||
self.get = self.schema.get
|
||||
self.schema.control = self
|
||||
|
||||
self.icon = icon
|
||||
self.icon = f'mdi:{icon}' if icon else icon
|
||||
self.icon
|
||||
|
||||
@property
|
||||
def name_sanitized(self):
|
||||
|
|
|
|||
0
haco/data/__init__.py
Normal file
0
haco/data/__init__.py
Normal file
36
haco/data/type_binary_sensor.py
Normal file
36
haco/data/type_binary_sensor.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
class DeviceClassBinarySensor:
|
||||
"""
|
||||
|
||||
Sourced from:
|
||||
https://www.home-assistant.io/integrations/binary_sensor/#device-class
|
||||
|
||||
"""
|
||||
NONE: type(None) = None # Generic on/off. This is the default and doesn’t need to be set.
|
||||
BATTERY: str = "battery" # on means low, off means normal
|
||||
BATTERY_CHARGING: str = "battery_charging" # on means charging, off means not charging
|
||||
CARBON_MONOXIDE: str = "carbon_monoxide" # on means carbon monoxide detected, off no carbon monoxide (clear)
|
||||
COLD: str = "cold" # on means cold, off means normal
|
||||
CONNECTIVITY: str = "connectivity" # on means connected, off means disconnected
|
||||
DOOR: str = "door" # on means open, off means closed
|
||||
GARAGE_DOOR: str = "garage_door" # on means open, off means closed
|
||||
GAS: str = "gas" # on means gas detected, off means no gas (clear)
|
||||
HEAT: str = "heat" # on means hot, off means normal
|
||||
LIGHT: str = "light" # on means light detected, off means no light
|
||||
LOCK: str = "lock" # on means open (unlocked), off means closed (locked)
|
||||
MOISTURE: str = "moisture" # on means moisture detected (wet), off means no moisture (dry)
|
||||
MOTION: str = "motion" # on means motion detected, off means no motion (clear)
|
||||
MOVING: str = "moving" # on means moving, off means not moving (stopped)
|
||||
OCCUPANCY: str = "occupancy" # on means occupied (detected), off means not occupied (clear)
|
||||
OPENING: str = "opening" # on means open, off means closed
|
||||
PLUG: str = "plug" # on means device is plugged in, off means device is unplugged
|
||||
POWER: str = "power" # on means power detected, off means no power
|
||||
PRESENCE: str = "presence" # on means home, off means away
|
||||
PROBLEM: str = "problem" # on means problem detected, off means no problem (OK)
|
||||
RUNNING: str = "running" # on means running, off means not running
|
||||
SAFETY: str = "safety" # on means unsafe, off means safe
|
||||
SMOKE: str = "smoke" # on means smoke detected, off means no smoke (clear)
|
||||
SOUND: str = "sound" # on means sound detected, off means no sound (clear)
|
||||
TAMPER: str = "tamper" # on means tampering detected, off means no tampering (clear)
|
||||
UPDATE: str = "update" # on means update available, off means up-to-date
|
||||
VIBRATION: str = "vibration" # on means vibration detected, off means no vibration (clear)
|
||||
WINDOW: str = "window" # on means open, off means closed
|
||||
58
haco/data/type_sensor.py
Normal file
58
haco/data/type_sensor.py
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
class DeviceClassSensor:
|
||||
"""
|
||||
|
||||
Sourced from:
|
||||
https://www.home-assistant.io/integrations/sensor/#device-class
|
||||
|
||||
"""
|
||||
NONE: type(None) = None # Generic sensor. This is the default and doesn’t need to be set.
|
||||
APPARENT_POWER: str = "apparent_power" # Apparent power in VA.
|
||||
AQI: str = "aqi" # Air Quality Index (unitless).
|
||||
ATMOSPHERIC_PRESSURE: str = "atmospheric_pressure" # Atmospheric pressure in cbar, bar, hPa, inHg, kPa, mbar, Pa, or psi.
|
||||
BATTERY: str = "battery" # Percentage of battery that is left in %.
|
||||
CARBON_DIOXIDE: str = "carbon_dioxide" # Carbon Dioxide in CO2 (Smoke) in ppm.
|
||||
CARBON_MONOXIDE: str = "carbon_monoxide" # Carbon Monoxide in CO (Gas CNG/LPG) in ppm.
|
||||
CURRENT: str = "current" # Current in A or mA.
|
||||
DATA_RATE: str = "data_rate" # Data rate in bit/s, kbit/s, Mbit/s, Gbit/s, B/s, kB/s, MB/s, GB/s, KiB/s, MiB/s, or GiB/s.
|
||||
DATA_SIZE: str = "data_size" # Data size in bit, kbit, Mbit, Gbit, B, kB, MB, GB, TB, PB, EB, ZB, YB, KiB, MiB, GiB, TiB, PiB, EiB, ZiB, or YiB.
|
||||
DATE: str = "date" # Date string (ISO 8601).
|
||||
DISTANCE: str = "distance" # Generic distance in km, m, cm, mm, mi, yd, or in.
|
||||
DURATION: str = "duration" # Duration in d, h, min, or s.
|
||||
ENERGY: str = "energy" # Energy in Wh, kWh, MWh, MJ, or GJ.
|
||||
ENERGY_STORAGE: str = "energy_storage" # Stored energy in Wh, kWh, MWh, MJ, or GJ.
|
||||
ENUM: str = "enum" # Has a limited set of (non-numeric) states.
|
||||
FREQUENCY: str = "frequency" # Frequency in Hz, kHz, MHz, or GHz.
|
||||
GAS: str = "gas" # Gas volume in m³, ft³, or CCF.
|
||||
HUMIDITY: str = "humidity" # Percentage of humidity in the air in %.
|
||||
ILLUMINANCE: str = "illuminance" # The current light level in lx.
|
||||
IRRADIANCE: str = "irradiance" # Irradiance in W/m² or BTU/(h⋅ft²).
|
||||
MOISTURE: str = "moisture" # Percentage of water in a substance in %.
|
||||
MONETARY: str = "monetary" # The monetary value (ISO 4217).
|
||||
NITROGEN_DIOXIDE: str = "nitrogen_dioxide" # Concentration of Nitrogen Dioxide in µg/m³.
|
||||
NITROGEN_MONOXIDE: str = "nitrogen_monoxide" # Concentration of Nitrogen Monoxide in µg/m³.
|
||||
NITROUS_OXIDE: str = "nitrous_oxide" # Concentration of Nitrous Oxide in µg/m³.
|
||||
OZONE: str = "ozone" # Concentration of Ozone in µg/m³.
|
||||
PH: str = "ph" # Potential hydrogen (pH) value of a water solution.
|
||||
PM1: str = "pm1" # Concentration of particulate matter less than 1 micrometer in µg/m³.
|
||||
PM25: str = "pm25" # Concentration of particulate matter less than 2.5 micrometers in µg/m³.
|
||||
PM10: str = "pm10" # Concentration of particulate matter less than 10 micrometers in µg/m³.
|
||||
POWER_FACTOR: str = "power_factor" # Power factor (unitless), unit may be None or %.
|
||||
POWER: str = "power" # Power in W or kW.
|
||||
PRECIPITATION: str = "precipitation" # Accumulated precipitation in cm, in, or mm.
|
||||
PRECIPITATION_INTENSITY: str = "precipitation_intensity" # Precipitation intensity in in/d, in/h, mm/d, or mm/h.
|
||||
PRESSURE: str = "pressure" # Pressure in Pa, kPa, hPa, bar, cbar, mbar, mmHg, inHg, or psi.
|
||||
REACTIVE_POWER: str = "reactive_power" # Reactive power in var.
|
||||
SIGNAL_STRENGTH: str = "signal_strength" # Signal strength in dB or dBm.
|
||||
SOUND_PRESSURE: str = "sound_pressure" # Sound pressure in dB or dBA.
|
||||
SPEED: str = "speed" # Generic speed in ft/s, in/d, in/h, km/h, kn, m/s, mph, or mm/d.
|
||||
SULPHUR_DIOXIDE: str = "sulphur_dioxide" # Concentration of sulphur dioxide in µg/m³.
|
||||
TEMPERATURE: str = "temperature" # Temperature in °C, °F, or K.
|
||||
TIMESTAMP: str = "timestamp" # Datetime object or timestamp string (ISO 8601).
|
||||
VOLATILE_ORGANIC_COMPOUNDS: str = "volatile_organic_compounds" # Concentration of volatile organic compounds in µg/m³.
|
||||
VOLATILE_ORGANIC_COMPOUNDS_PARTS: str = "volatile_organic_compounds_parts" # Ratio of volatile organic compounds in ppm or ppb.
|
||||
VOLTAGE: str = "voltage" # Voltage in V or mV.
|
||||
VOLUME: str = "volume" # Generic volume in L, mL, gal, fl. oz., m³, ft³, or CCF.
|
||||
VOLUME_STORAGE: str = "volume_storage" # Generic stored volume in L, mL, gal, fl. oz., m³, ft³, or CCF.
|
||||
WATER: str = "water" # Water consumption in L, gal, m³, ft³, or CCF.
|
||||
WEIGHT: str = "weight" # Generic mass in kg, g, mg, µg, oz, lb, or st.
|
||||
WIND_SPEED: str = "wind_speed" # Wind speed in ft/s, km/h, kn, m/s, or mph.
|
||||
138
haco/data/uom.py
Normal file
138
haco/data/uom.py
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
class Uom:
|
||||
"""
|
||||
|
||||
Sourced from: https://github.com/home-assistant/core/blob/03b1c7ad1deb4b9494df01b27ef8e1d7dfe179ba/homeassistant/const.py#L489C1-L489C1
|
||||
|
||||
"""
|
||||
POWER_WATT: str = "W"
|
||||
POWER_KILO_WATT: str = "kW"
|
||||
|
||||
VOLT: str = "V"
|
||||
|
||||
ENERGY_WATT_HOUR: str = "Wh"
|
||||
ENERGY_KILO_WATT_HOUR: str = "kWh"
|
||||
|
||||
ELECTRICAL_CURRENT_AMPERE: str = "A"
|
||||
ELECTRICAL_VOLT_AMPERE: str = "VA"
|
||||
|
||||
DEGREE: str = "°"
|
||||
|
||||
CURRENCY_EURO: str = "€"
|
||||
CURRENCY_DOLLAR: str = "$"
|
||||
CURRENCY_CENT: str = "¢"
|
||||
|
||||
TEMP_CELSIUS: str = "°C"
|
||||
TEMP_FAHRENHEIT: str = "°F"
|
||||
TEMP_KELVIN: str = "K"
|
||||
|
||||
TIME_MICROSECONDS: str = "μs"
|
||||
TIME_MILLISECONDS: str = "ms"
|
||||
TIME_SECONDS: str = "s"
|
||||
TIME_MINUTES: str = "min"
|
||||
TIME_HOURS: str = "h"
|
||||
TIME_DAYS: str = "d"
|
||||
TIME_WEEKS: str = "w"
|
||||
TIME_MONTHS: str = "m"
|
||||
TIME_YEARS: str = "y"
|
||||
|
||||
LENGTH_MILLIMETERS: str = "mm"
|
||||
LENGTH_CENTIMETERS: str = "cm"
|
||||
LENGTH_METERS: str = "m"
|
||||
LENGTH_KILOMETERS: str = "km"
|
||||
|
||||
LENGTH_INCHES: str = "in"
|
||||
LENGTH_FEET: str = "ft"
|
||||
LENGTH_YARD: str = "yd"
|
||||
LENGTH_MILES: str = "mi"
|
||||
|
||||
FREQUENCY_HERTZ: str = "Hz"
|
||||
FREQUENCY_GIGAHERTZ: str = "GHz"
|
||||
|
||||
PRESSURE_PA: str = "Pa"
|
||||
PRESSURE_HPA: str = "hPa"
|
||||
PRESSURE_BAR: str = "bar"
|
||||
PRESSURE_MBAR: str = "mbar"
|
||||
PRESSURE_INHG: str = "inHg"
|
||||
PRESSURE_PSI: str = "psi"
|
||||
|
||||
VOLUME_LITERS: str = "L"
|
||||
VOLUME_MILLILITERS: str = "mL"
|
||||
VOLUME_CUBIC_METERS: str = "m³"
|
||||
VOLUME_CUBIC_FEET: str = "ft³"
|
||||
|
||||
VOLUME_GALLONS: str = "gal"
|
||||
VOLUME_FLUID_OUNCE: str = "fl. oz."
|
||||
|
||||
VOLUME_FLOW_RATE_CUBIC_METERS_PER_HOUR: str = "m³/h"
|
||||
VOLUME_FLOW_RATE_CUBIC_FEET_PER_MINUTE: str = "ft³/m"
|
||||
|
||||
AREA_SQUARE_METERS: str = "m²"
|
||||
|
||||
MASS_GRAMS: str = "g"
|
||||
MASS_KILOGRAMS: str = "kg"
|
||||
MASS_MILLIGRAMS: str = "mg"
|
||||
MASS_MICROGRAMS: str = "µg"
|
||||
|
||||
MASS_OUNCES: str = "oz"
|
||||
MASS_POUNDS: str = "lb"
|
||||
|
||||
CONDUCTIVITY: str = "µS/cm"
|
||||
|
||||
LIGHT_LUX: str = "lx"
|
||||
|
||||
UV_INDEX: str = "UV index"
|
||||
|
||||
PERCENTAGE: str = "%"
|
||||
|
||||
IRRADIATION_WATTS_PER_SQUARE_METER: str = "W/m²"
|
||||
|
||||
PRECIPITATION_MILLIMETERS_PER_HOUR: str = "mm/h"
|
||||
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER: str = "µg/m³"
|
||||
CONCENTRATION_MILLIGRAMS_PER_CUBIC_METER: str = "mg/m³"
|
||||
CONCENTRATION_PARTS_PER_CUBIC_METER: str = "p/m³"
|
||||
CONCENTRATION_PARTS_PER_MILLION: str = "ppm"
|
||||
CONCENTRATION_PARTS_PER_BILLION: str = "ppb"
|
||||
|
||||
SPEED_MILLIMETERS_PER_DAY: str = "mm/d"
|
||||
SPEED_INCHES_PER_DAY: str = "in/d"
|
||||
SPEED_METERS_PER_SECOND: str = "m/s"
|
||||
SPEED_INCHES_PER_HOUR: str = "in/h"
|
||||
SPEED_KILOMETERS_PER_HOUR: str = "km/h"
|
||||
SPEED_MILES_PER_HOUR: str = "mph"
|
||||
|
||||
SIGNAL_STRENGTH_DECIBELS: str = "dB"
|
||||
SIGNAL_STRENGTH_DECIBELS_MILLIWATT: str = "dBm"
|
||||
|
||||
DATA_BITS: str = "bit"
|
||||
DATA_KILOBITS: str = "kbit"
|
||||
DATA_MEGABITS: str = "Mbit"
|
||||
DATA_GIGABITS: str = "Gbit"
|
||||
DATA_BYTES: str = "B"
|
||||
DATA_KILOBYTES: str = "kB"
|
||||
DATA_MEGABYTES: str = "MB"
|
||||
DATA_GIGABYTES: str = "GB"
|
||||
DATA_TERABYTES: str = "TB"
|
||||
DATA_PETABYTES: str = "PB"
|
||||
DATA_EXABYTES: str = "EB"
|
||||
DATA_ZETTABYTES: str = "ZB"
|
||||
DATA_YOTTABYTES: str = "YB"
|
||||
DATA_KIBIBYTES: str = "KiB"
|
||||
DATA_MEBIBYTES: str = "MiB"
|
||||
DATA_GIBIBYTES: str = "GiB"
|
||||
DATA_TEBIBYTES: str = "TiB"
|
||||
DATA_PEBIBYTES: str = "PiB"
|
||||
DATA_EXBIBYTES: str = "EiB"
|
||||
DATA_ZEBIBYTES: str = "ZiB"
|
||||
DATA_YOBIBYTES: str = "YiB"
|
||||
DATA_RATE_BITS_PER_SECOND: str = "bit/s"
|
||||
DATA_RATE_KILOBITS_PER_SECOND: str = "kbit/s"
|
||||
DATA_RATE_MEGABITS_PER_SECOND: str = "Mbit/s"
|
||||
DATA_RATE_GIGABITS_PER_SECOND: str = "Gbit/s"
|
||||
DATA_RATE_BYTES_PER_SECOND: str = "B/s"
|
||||
DATA_RATE_KILOBYTES_PER_SECOND: str = "kB/s"
|
||||
DATA_RATE_MEGABYTES_PER_SECOND: str = "MB/s"
|
||||
DATA_RATE_GIGABYTES_PER_SECOND: str = "GB/s"
|
||||
DATA_RATE_KIBIBYTES_PER_SECOND: str = "KiB/s"
|
||||
DATA_RATE_MEBIBYTES_PER_SECOND: str = "MiB/s"
|
||||
DATA_RATE_GIBIBYTES_PER_SECOND: str = "GiB/s"
|
||||
|
|
@ -1,10 +1,16 @@
|
|||
from haco import schema
|
||||
from haco.control import Control
|
||||
from haco.data.type_sensor import DeviceClassSensor
|
||||
|
||||
from haco.data.uom import Uom
|
||||
|
||||
|
||||
class Sensor(Control):
|
||||
NAME = 'sensor'
|
||||
|
||||
DEVICE_CLASS = DeviceClassSensor
|
||||
UOM = Uom
|
||||
|
||||
@classmethod
|
||||
def get_schema(cls):
|
||||
return schema.Schema(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue