mirror of
https://github.com/andvikt/mega_hacs.git
synced 2025-12-12 01:24:29 +05:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d15cce8061 | ||
|
|
4e83d81004 | ||
|
|
9ceb544c1a | ||
|
|
c8b3cb60de | ||
|
|
bd550442d4 | ||
|
|
8903628b36 | ||
|
|
e1a6637f28 | ||
|
|
a346cb3fd7 | ||
|
|
d6ef137e75 |
@@ -1,5 +1,5 @@
|
|||||||
[bumpversion]
|
[bumpversion]
|
||||||
current_version = 1.1.4
|
current_version = 1.1.501
|
||||||
parse = (?P<major>\d+)(\.(?P<minor>\d+))(\.(?P<patch>\d+))(?P<release>[bf]*)(?P<build>\d*)
|
parse = (?P<major>\d+)(\.(?P<minor>\d+))(\.(?P<patch>\d+))(?P<release>[bf]*)(?P<build>\d*)
|
||||||
commit = True
|
commit = True
|
||||||
tag = True
|
tag = True
|
||||||
|
|||||||
@@ -136,10 +136,10 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
CUSTOMIZE_PORT,
|
CUSTOMIZE_PORT,
|
||||||
CUSTOMIZE_DS2413,
|
CUSTOMIZE_DS2413,
|
||||||
),
|
),
|
||||||
vol.Optional(CONF_FILTER_VALUES): [cv.positive_float],
|
vol.Optional(CONF_FILTER_VALUES): [vol.Coerce(float)],
|
||||||
vol.Optional(CONF_FILTER_SCALE): cv.positive_float,
|
vol.Optional(CONF_FILTER_SCALE): vol.Coerce(float),
|
||||||
vol.Optional(CONF_FILTER_LOW): cv.positive_float,
|
vol.Optional(CONF_FILTER_LOW): vol.Coerce(float),
|
||||||
vol.Optional(CONF_FILTER_HIGH): cv.positive_float,
|
vol.Optional(CONF_FILTER_HIGH): vol.Coerce(float),
|
||||||
},
|
},
|
||||||
vol.Optional(CONF_1WBUS): [OWBUS]
|
vol.Optional(CONF_1WBUS): [OWBUS]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from functools import partial
|
|||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_NAME
|
from homeassistant.const import CONF_NAME
|
||||||
from homeassistant.core import State
|
from homeassistant.core import State
|
||||||
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
from homeassistant.helpers.restore_state import RestoreEntity
|
from homeassistant.helpers.restore_state import RestoreEntity
|
||||||
from . import hub as h
|
from . import hub as h
|
||||||
@@ -142,7 +143,7 @@ class BaseMegaEntity(CoordinatorEntity, RestoreEntity):
|
|||||||
return self._customize
|
return self._customize
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self):
|
def device_info(self) -> DeviceInfo:
|
||||||
if isinstance(self.port, list):
|
if isinstance(self.port, list):
|
||||||
pt_idx = self.id_suffix
|
pt_idx = self.id_suffix
|
||||||
else:
|
else:
|
||||||
@@ -151,19 +152,16 @@ class BaseMegaEntity(CoordinatorEntity, RestoreEntity):
|
|||||||
pt_idx, _ = _pt.split('e')
|
pt_idx, _ = _pt.split('e')
|
||||||
else:
|
else:
|
||||||
pt_idx = _pt
|
pt_idx = _pt
|
||||||
return {
|
return DeviceInfo(
|
||||||
"identifiers": {
|
identifiers={
|
||||||
# Serial numbers are unique identifiers within a specific domain
|
# Serial numbers are unique identifiers within a specific domain
|
||||||
(DOMAIN, f'{self._mega_id}', pt_idx),
|
(DOMAIN, f'{self._mega_id}:{pt_idx}')
|
||||||
},
|
},
|
||||||
"config_entries": [
|
name=self.name,
|
||||||
self.config_entry,
|
manufacturer='ab-log.ru',
|
||||||
],
|
sw_version=self.mega.fw,
|
||||||
"name": f'{self._mega_id} port {pt_idx}' if not isinstance(self.port, list) else f'{self._mega_id} {pt_idx}',
|
via_device=(DOMAIN, self._mega_id),
|
||||||
"manufacturer": 'ab-log.ru',
|
)
|
||||||
"sw_version": self.mega.fw,
|
|
||||||
"via_device": (DOMAIN, self._mega_id),
|
|
||||||
}
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def lg(self) -> logging.Logger:
|
def lg(self) -> logging.Logger:
|
||||||
|
|||||||
@@ -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'),
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ class MegaRGBW(LightEntity, BaseMegaEntity):
|
|||||||
def max_values(self) -> list:
|
def max_values(self) -> list:
|
||||||
if self._max_values is None:
|
if self._max_values is None:
|
||||||
if self.is_ws:
|
if self.is_ws:
|
||||||
self._max_values = [255] * 3
|
self._max_values = [255] * 4
|
||||||
else:
|
else:
|
||||||
self._max_values = [
|
self._max_values = [
|
||||||
255 if isinstance(x, int) else 4095 for x in self.port
|
255 if isinstance(x, int) else 4095 for x in self.port
|
||||||
|
|||||||
@@ -15,5 +15,5 @@
|
|||||||
"@andvikt"
|
"@andvikt"
|
||||||
],
|
],
|
||||||
"issue_tracker": "https://github.com/andvikt/mega_hacs/issues",
|
"issue_tracker": "https://github.com/andvikt/mega_hacs/issues",
|
||||||
"version": "v1.1.4"
|
"version": "v1.1.501"
|
||||||
}
|
}
|
||||||
@@ -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:
|
||||||
@@ -231,8 +229,8 @@ class Mega1WSensor(FilterBadValues):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
unit_of_measurement,
|
unit_of_measurement=None,
|
||||||
device_class,
|
device_class=None,
|
||||||
key=None,
|
key=None,
|
||||||
*args,
|
*args,
|
||||||
**kwargs
|
**kwargs
|
||||||
|
|||||||
Reference in New Issue
Block a user