mirror of
https://github.com/andvikt/mega_hacs.git
synced 2025-12-11 17:14:28 +05:00
fix #138
This commit is contained in:
@@ -9,10 +9,10 @@ import re
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
from homeassistant.components.sensor import SensorDeviceClass
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import ( TEMP_CELSIUS, PERCENTAGE, LIGHT_LUX
|
||||||
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_PRESSURE,
|
|
||||||
DEVICE_CLASS_ILLUMINANCE, TEMP_CELSIUS, PERCENTAGE, LIGHT_LUX
|
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
@@ -45,10 +45,10 @@ UNITS = {
|
|||||||
LUX: LIGHT_LUX
|
LUX: LIGHT_LUX
|
||||||
}
|
}
|
||||||
CLASSES = {
|
CLASSES = {
|
||||||
TEMP: DEVICE_CLASS_TEMPERATURE,
|
TEMP: SensorDeviceClass.TEMPERATURE,
|
||||||
HUM: DEVICE_CLASS_HUMIDITY,
|
HUM: SensorDeviceClass.HUMIDITY,
|
||||||
PRESS: DEVICE_CLASS_PRESSURE,
|
PRESS: SensorDeviceClass.PRESSURE,
|
||||||
LUX: DEVICE_CLASS_ILLUMINANCE
|
LUX: SensorDeviceClass.ILLUMINANCE
|
||||||
}
|
}
|
||||||
I2C_DEVICE_TYPES = {
|
I2C_DEVICE_TYPES = {
|
||||||
"2": LUX, # BH1750
|
"2": LUX, # BH1750
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
import typing
|
import typing
|
||||||
from dataclasses import dataclass, field, astuple
|
from dataclasses import dataclass, astuple
|
||||||
from urllib.parse import parse_qsl, urlparse
|
from urllib.parse import parse_qsl, urlparse
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
from homeassistant.components.sensor import SensorDeviceClass
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
DEVICE_CLASS_HUMIDITY,
|
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
|
||||||
DEVICE_CLASS_ILLUMINANCE,
|
|
||||||
DEVICE_CLASS_PRESSURE,
|
|
||||||
DEVICE_CLASS_CO2,
|
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
LIGHT_LUX,
|
LIGHT_LUX,
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
@@ -16,11 +13,11 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
|
|
||||||
# DeviceType = namedtuple('DeviceType', 'device_class,unit_of_measurement,suffix')
|
# DeviceType = namedtuple('DeviceType', 'device_class,unit_of_measurement,suffix')
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class DeviceType:
|
class DeviceType:
|
||||||
|
|
||||||
device_class: typing.Optional[str] = None
|
device_class: typing.Optional[str] = None
|
||||||
unit_of_measurement: typing.Optional[str] = None
|
unit_of_measurement: typing.Optional[str] = None
|
||||||
suffix: typing.Optional[str] = None
|
suffix: typing.Optional[str] = None
|
||||||
@@ -89,55 +86,55 @@ class Request:
|
|||||||
|
|
||||||
i2c_classes = {
|
i2c_classes = {
|
||||||
'htu21d': [
|
'htu21d': [
|
||||||
DeviceType(DEVICE_CLASS_HUMIDITY, PERCENTAGE, None),
|
DeviceType(SensorDeviceClass.HUMIDITY, PERCENTAGE, None),
|
||||||
DeviceType(DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None),
|
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None),
|
||||||
],
|
],
|
||||||
'sht31': [
|
'sht31': [
|
||||||
DeviceType(DEVICE_CLASS_HUMIDITY, PERCENTAGE, None, delay=1.5),
|
DeviceType(SensorDeviceClass.HUMIDITY, PERCENTAGE, None, delay=1.5),
|
||||||
DeviceType(DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None),
|
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None),
|
||||||
],
|
],
|
||||||
'max44009': [
|
'max44009': [
|
||||||
DeviceType(DEVICE_CLASS_ILLUMINANCE, LIGHT_LUX, None)
|
DeviceType(SensorDeviceClass.ILLUMINANCE, LIGHT_LUX, None)
|
||||||
],
|
],
|
||||||
'bh1750': [
|
'bh1750': [
|
||||||
DeviceType(DEVICE_CLASS_ILLUMINANCE, LIGHT_LUX, None)
|
DeviceType(SensorDeviceClass.ILLUMINANCE, LIGHT_LUX, None)
|
||||||
],
|
],
|
||||||
'tsl2591': [
|
'tsl2591': [
|
||||||
DeviceType(DEVICE_CLASS_ILLUMINANCE, LIGHT_LUX, None)
|
DeviceType(SensorDeviceClass.ILLUMINANCE, LIGHT_LUX, None)
|
||||||
],
|
],
|
||||||
'bmp180': [
|
'bmp180': [
|
||||||
DeviceType(DEVICE_CLASS_PRESSURE, PRESSURE_BAR, None),
|
DeviceType(SensorDeviceClass.PRESSURE, PRESSURE_BAR, None),
|
||||||
DeviceType(DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None),
|
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None),
|
||||||
],
|
],
|
||||||
'bmx280': [
|
'bmx280': [
|
||||||
DeviceType(DEVICE_CLASS_PRESSURE, PRESSURE_BAR, None),
|
DeviceType(SensorDeviceClass.PRESSURE, PRESSURE_BAR, None),
|
||||||
DeviceType(DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None),
|
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None),
|
||||||
DeviceType(DEVICE_CLASS_HUMIDITY, PERCENTAGE, None)
|
DeviceType(SensorDeviceClass.HUMIDITY, PERCENTAGE, None)
|
||||||
],
|
],
|
||||||
'dps368': [
|
'dps368': [
|
||||||
DeviceType(DEVICE_CLASS_PRESSURE, PRESSURE_BAR, None),
|
DeviceType(SensorDeviceClass.PRESSURE, PRESSURE_BAR, None),
|
||||||
DeviceType(DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None),
|
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None),
|
||||||
],
|
],
|
||||||
'mlx90614': [
|
'mlx90614': [
|
||||||
Skip,
|
Skip,
|
||||||
DeviceType(DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, 'temp'),
|
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, 'temp'),
|
||||||
DeviceType(DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, 'object'),
|
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, 'object'),
|
||||||
],
|
],
|
||||||
'ptsensor': [
|
'ptsensor': [
|
||||||
Skip,
|
Skip,
|
||||||
Request(delay=3), # запрос на измерение
|
Request(delay=3), # запрос на измерение
|
||||||
DeviceType(DEVICE_CLASS_PRESSURE, PRESSURE_BAR, None),
|
DeviceType(SensorDeviceClass.PRESSURE, PRESSURE_BAR, None),
|
||||||
DeviceType(DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None),
|
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None),
|
||||||
],
|
],
|
||||||
'mcp9600': [
|
'mcp9600': [
|
||||||
DeviceType(DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None), # термопара
|
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None), # термопара
|
||||||
DeviceType(DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None), # сенсор встроенный в микросхему
|
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None), # сенсор встроенный в микросхему
|
||||||
],
|
],
|
||||||
't67xx': [
|
't67xx': [
|
||||||
DeviceType(DEVICE_CLASS_CO2, CONCENTRATION_PARTS_PER_MILLION, None)
|
DeviceType(SensorDeviceClass.CO2, CONCENTRATION_PARTS_PER_MILLION, None)
|
||||||
],
|
],
|
||||||
'tmp117': [
|
'tmp117': [
|
||||||
DeviceType(DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None),
|
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None),
|
||||||
],
|
],
|
||||||
'ads1115': [
|
'ads1115': [
|
||||||
DeviceType(None, None, 'ch0'),
|
DeviceType(None, None, 'ch0'),
|
||||||
|
|||||||
@@ -4,9 +4,7 @@ import voluptuous as vol
|
|||||||
import struct
|
import struct
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
PLATFORM_SCHEMA as SENSOR_SCHEMA,
|
PLATFORM_SCHEMA as SENSOR_SCHEMA, SensorEntity, SensorDeviceClass
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
|
||||||
DEVICE_CLASS_HUMIDITY, SensorEntity
|
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@@ -40,8 +38,8 @@ UNITS = {
|
|||||||
HUM: '%'
|
HUM: '%'
|
||||||
}
|
}
|
||||||
CLASSES = {
|
CLASSES = {
|
||||||
TEMP: DEVICE_CLASS_TEMPERATURE,
|
TEMP: SensorDeviceClass.TEMPERATURE,
|
||||||
HUM: DEVICE_CLASS_HUMIDITY
|
HUM: SensorDeviceClass.HUMIDITY
|
||||||
}
|
}
|
||||||
# Validation of the user's configuration
|
# Validation of the user's configuration
|
||||||
_ITEM = {
|
_ITEM = {
|
||||||
@@ -118,15 +116,15 @@ class FilterBadValues(MegaPushEntity, SensorEntity):
|
|||||||
try:
|
try:
|
||||||
if value \
|
if value \
|
||||||
in self.filter_values \
|
in self.filter_values \
|
||||||
or (self.filter_low is not None and value < self.filter_low) \
|
or (self.filter_low is not None and value < self.filter_low) \
|
||||||
or (self.filter_high is not None and value > self.filter_high) \
|
or (self.filter_high is not None and value > self.filter_high) \
|
||||||
or (
|
or (
|
||||||
self._prev_value is not None
|
self._prev_value is not None
|
||||||
and self.filter_scale is not None
|
and self.filter_scale is not None
|
||||||
and (
|
and (
|
||||||
abs(value - self._prev_value) / self._prev_value > self.filter_scale
|
abs(value - self._prev_value) / self._prev_value > self.filter_scale
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
if self.fill_na == 'last':
|
if self.fill_na == 'last':
|
||||||
value = self._prev_value
|
value = self._prev_value
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user