mirror of
https://github.com/andvikt/mega_hacs.git
synced 2025-12-12 01:24:29 +05:00
Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cd5ab3b689 | ||
|
|
0138f5e323 | ||
|
|
0ab4f6623c | ||
|
|
5664e1e929 | ||
|
|
bcf108fc9c | ||
|
|
ca3f90374b | ||
|
|
d15cce8061 | ||
|
|
4e83d81004 | ||
|
|
9ceb544c1a | ||
|
|
c8b3cb60de | ||
|
|
bd550442d4 | ||
|
|
8903628b36 | ||
|
|
e1a6637f28 | ||
|
|
a346cb3fd7 | ||
|
|
d6ef137e75 | ||
|
|
d7180c0477 | ||
|
|
1ceb7e4766 | ||
|
|
ef46ac2b2b | ||
|
|
e44aef35fb | ||
|
|
a860ba9822 | ||
|
|
2463b270e5 | ||
|
|
ce2969c1e7 | ||
|
|
34056273f3 |
@@ -1,5 +1,5 @@
|
||||
[bumpversion]
|
||||
current_version = 1.1.1
|
||||
current_version = 1.1.6b1
|
||||
parse = (?P<major>\d+)(\.(?P<minor>\d+))(\.(?P<patch>\d+))(?P<release>[bf]*)(?P<build>\d*)
|
||||
commit = True
|
||||
tag = True
|
||||
|
||||
@@ -136,10 +136,10 @@ CONFIG_SCHEMA = vol.Schema(
|
||||
CUSTOMIZE_PORT,
|
||||
CUSTOMIZE_DS2413,
|
||||
),
|
||||
vol.Optional(CONF_FILTER_VALUES): [cv.positive_float],
|
||||
vol.Optional(CONF_FILTER_SCALE): cv.positive_float,
|
||||
vol.Optional(CONF_FILTER_LOW): cv.positive_float,
|
||||
vol.Optional(CONF_FILTER_HIGH): cv.positive_float,
|
||||
vol.Optional(CONF_FILTER_VALUES): [vol.Coerce(float)],
|
||||
vol.Optional(CONF_FILTER_SCALE): vol.Coerce(float),
|
||||
vol.Optional(CONF_FILTER_LOW): vol.Coerce(float),
|
||||
vol.Optional(CONF_FILTER_HIGH): vol.Coerce(float),
|
||||
},
|
||||
vol.Optional(CONF_1WBUS): [OWBUS]
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ from functools import partial
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_NAME
|
||||
from homeassistant.core import State
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
from . import hub as h
|
||||
@@ -142,7 +143,7 @@ class BaseMegaEntity(CoordinatorEntity, RestoreEntity):
|
||||
return self._customize
|
||||
|
||||
@property
|
||||
def device_info(self):
|
||||
def device_info(self) -> DeviceInfo:
|
||||
if isinstance(self.port, list):
|
||||
pt_idx = self.id_suffix
|
||||
else:
|
||||
@@ -151,19 +152,16 @@ class BaseMegaEntity(CoordinatorEntity, RestoreEntity):
|
||||
pt_idx, _ = _pt.split('e')
|
||||
else:
|
||||
pt_idx = _pt
|
||||
return {
|
||||
"identifiers": {
|
||||
return DeviceInfo(
|
||||
identifiers={
|
||||
# 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": [
|
||||
self.config_entry,
|
||||
],
|
||||
"name": f'{self._mega_id} port {pt_idx}' if not isinstance(self.port, list) else f'{self._mega_id} {pt_idx}',
|
||||
"manufacturer": 'ab-log.ru',
|
||||
"sw_version": self.mega.fw,
|
||||
"via_device": (DOMAIN, self._mega_id),
|
||||
}
|
||||
name=self.name,
|
||||
manufacturer='ab-log.ru',
|
||||
sw_version=self.mega.fw,
|
||||
via_device=(DOMAIN, self._mega_id),
|
||||
)
|
||||
|
||||
@property
|
||||
def lg(self) -> logging.Logger:
|
||||
|
||||
@@ -9,10 +9,10 @@ import re
|
||||
import json
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from homeassistant.components.sensor import SensorDeviceClass
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_PRESSURE,
|
||||
DEVICE_CLASS_ILLUMINANCE, TEMP_CELSIUS, PERCENTAGE, LIGHT_LUX
|
||||
from homeassistant.const import ( TEMP_CELSIUS, PERCENTAGE, LIGHT_LUX
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
@@ -45,10 +45,10 @@ UNITS = {
|
||||
LUX: LIGHT_LUX
|
||||
}
|
||||
CLASSES = {
|
||||
TEMP: DEVICE_CLASS_TEMPERATURE,
|
||||
HUM: DEVICE_CLASS_HUMIDITY,
|
||||
PRESS: DEVICE_CLASS_PRESSURE,
|
||||
LUX: DEVICE_CLASS_ILLUMINANCE
|
||||
TEMP: SensorDeviceClass.TEMPERATURE,
|
||||
HUM: SensorDeviceClass.HUMIDITY,
|
||||
PRESS: SensorDeviceClass.PRESSURE,
|
||||
LUX: SensorDeviceClass.ILLUMINANCE
|
||||
}
|
||||
I2C_DEVICE_TYPES = {
|
||||
"2": LUX, # BH1750
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import typing
|
||||
from dataclasses import dataclass, field, astuple
|
||||
from dataclasses import dataclass, astuple
|
||||
from urllib.parse import parse_qsl, urlparse
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from homeassistant.components.sensor import SensorDeviceClass
|
||||
from homeassistant.const import (
|
||||
DEVICE_CLASS_HUMIDITY,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
DEVICE_CLASS_ILLUMINANCE,
|
||||
DEVICE_CLASS_PRESSURE,
|
||||
DEVICE_CLASS_CO2,
|
||||
PERCENTAGE,
|
||||
LIGHT_LUX,
|
||||
TEMP_CELSIUS,
|
||||
@@ -16,11 +13,11 @@ from homeassistant.const import (
|
||||
)
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# DeviceType = namedtuple('DeviceType', 'device_class,unit_of_measurement,suffix')
|
||||
|
||||
@dataclass
|
||||
class DeviceType:
|
||||
|
||||
device_class: typing.Optional[str] = None
|
||||
unit_of_measurement: typing.Optional[str] = None
|
||||
suffix: typing.Optional[str] = None
|
||||
@@ -89,55 +86,55 @@ class Request:
|
||||
|
||||
i2c_classes = {
|
||||
'htu21d': [
|
||||
DeviceType(DEVICE_CLASS_HUMIDITY, PERCENTAGE, None),
|
||||
DeviceType(DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None),
|
||||
DeviceType(SensorDeviceClass.HUMIDITY, PERCENTAGE, None),
|
||||
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None),
|
||||
],
|
||||
'sht31': [
|
||||
DeviceType(DEVICE_CLASS_HUMIDITY, PERCENTAGE, None, delay=0.5),
|
||||
DeviceType(DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None),
|
||||
DeviceType(SensorDeviceClass.HUMIDITY, PERCENTAGE, None, delay=1.5),
|
||||
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None),
|
||||
],
|
||||
'max44009': [
|
||||
DeviceType(DEVICE_CLASS_ILLUMINANCE, LIGHT_LUX, None)
|
||||
DeviceType(SensorDeviceClass.ILLUMINANCE, LIGHT_LUX, None)
|
||||
],
|
||||
'bh1750': [
|
||||
DeviceType(DEVICE_CLASS_ILLUMINANCE, LIGHT_LUX, None)
|
||||
DeviceType(SensorDeviceClass.ILLUMINANCE, LIGHT_LUX, None)
|
||||
],
|
||||
'tsl2591': [
|
||||
DeviceType(DEVICE_CLASS_ILLUMINANCE, LIGHT_LUX, None)
|
||||
DeviceType(SensorDeviceClass.ILLUMINANCE, LIGHT_LUX, None)
|
||||
],
|
||||
'bmp180': [
|
||||
DeviceType(DEVICE_CLASS_PRESSURE, PRESSURE_BAR, None),
|
||||
DeviceType(DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None),
|
||||
DeviceType(SensorDeviceClass.PRESSURE, PRESSURE_BAR, None),
|
||||
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None),
|
||||
],
|
||||
'bmx280': [
|
||||
DeviceType(DEVICE_CLASS_PRESSURE, PRESSURE_BAR, None),
|
||||
DeviceType(DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None),
|
||||
DeviceType(DEVICE_CLASS_HUMIDITY, PERCENTAGE, None)
|
||||
DeviceType(SensorDeviceClass.PRESSURE, PRESSURE_BAR, None),
|
||||
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None),
|
||||
DeviceType(SensorDeviceClass.HUMIDITY, PERCENTAGE, None)
|
||||
],
|
||||
'dps368': [
|
||||
DeviceType(DEVICE_CLASS_PRESSURE, PRESSURE_BAR, None),
|
||||
DeviceType(DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None),
|
||||
DeviceType(SensorDeviceClass.PRESSURE, PRESSURE_BAR, None),
|
||||
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None),
|
||||
],
|
||||
'mlx90614': [
|
||||
Skip,
|
||||
DeviceType(DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, 'temp'),
|
||||
DeviceType(DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, 'object'),
|
||||
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, 'temp'),
|
||||
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, 'object'),
|
||||
],
|
||||
'ptsensor': [
|
||||
Skip,
|
||||
Request(delay=3), # запрос на измерение
|
||||
DeviceType(DEVICE_CLASS_PRESSURE, PRESSURE_BAR, None),
|
||||
DeviceType(DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None),
|
||||
DeviceType(SensorDeviceClass.PRESSURE, PRESSURE_BAR, None),
|
||||
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None),
|
||||
],
|
||||
'mcp9600': [
|
||||
DeviceType(DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None), # термопара
|
||||
DeviceType(DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None), # сенсор встроенный в микросхему
|
||||
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None), # термопара
|
||||
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None), # сенсор встроенный в микросхему
|
||||
],
|
||||
't67xx': [
|
||||
DeviceType(DEVICE_CLASS_CO2, CONCENTRATION_PARTS_PER_MILLION, None)
|
||||
DeviceType(SensorDeviceClass.CO2, CONCENTRATION_PARTS_PER_MILLION, None)
|
||||
],
|
||||
'tmp117': [
|
||||
DeviceType(DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, None),
|
||||
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None),
|
||||
],
|
||||
'ads1115': [
|
||||
DeviceType(None, None, 'ch0'),
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
"""Platform for light integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import typing
|
||||
@@ -14,8 +16,8 @@ from homeassistant.components.light import (
|
||||
SUPPORT_BRIGHTNESS,
|
||||
LightEntity,
|
||||
SUPPORT_TRANSITION,
|
||||
SUPPORT_COLOR,
|
||||
SUPPORT_WHITE_VALUE
|
||||
SUPPORT_COLOR, ColorMode, LightEntityFeature,
|
||||
# SUPPORT_WHITE_VALUE
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
@@ -116,6 +118,7 @@ class MegaRGBW(LightEntity, BaseMegaEntity):
|
||||
self._is_on = None
|
||||
self._brightness = None
|
||||
self._hs_color = None
|
||||
self._rgb_color: tuple[int, int, int] | None = None
|
||||
self._white_value = None
|
||||
self._task: asyncio.Task = None
|
||||
self._restore = None
|
||||
@@ -128,7 +131,7 @@ class MegaRGBW(LightEntity, BaseMegaEntity):
|
||||
def max_values(self) -> list:
|
||||
if self._max_values is None:
|
||||
if self.is_ws:
|
||||
self._max_values = [255] * 3
|
||||
self._max_values = [255] * 4
|
||||
else:
|
||||
self._max_values = [
|
||||
255 if isinstance(x, int) else 4095 for x in self.port
|
||||
@@ -143,10 +146,34 @@ class MegaRGBW(LightEntity, BaseMegaEntity):
|
||||
def is_ws(self):
|
||||
return self.customize.get(CONF_WS28XX)
|
||||
|
||||
|
||||
@property
|
||||
def supported_color_modes(self) -> set[ColorMode] | set[str] | None:
|
||||
return {
|
||||
ColorMode.BRIGHTNESS,
|
||||
ColorMode.RGB if len(self.port) != 4 else ColorMode.RGBW
|
||||
}
|
||||
|
||||
@property
|
||||
def color_mode(self) -> ColorMode | str | None:
|
||||
if len(self.port) == 4:
|
||||
return ColorMode.RGBW
|
||||
else:
|
||||
return ColorMode.RGB
|
||||
|
||||
@property
|
||||
def white_value(self):
|
||||
if self.supported_features & SUPPORT_WHITE_VALUE:
|
||||
return float(self.get_attribute('white_value', 0))
|
||||
# if self.supported_features & SUPPORT_WHITE_VALUE:
|
||||
return float(self.get_attribute('white_value', 0))
|
||||
|
||||
@property
|
||||
def rgb_color(self) -> tuple[int, int, int] | None:
|
||||
return self._rgb_color
|
||||
|
||||
@property
|
||||
def rgbw_color(self) -> tuple[int, int, int, int] | None:
|
||||
if self._white_value is not None and self._rgb_color is not None:
|
||||
return (*self._rgb_color, self._white_value)
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
@@ -162,12 +189,7 @@ class MegaRGBW(LightEntity, BaseMegaEntity):
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
return (
|
||||
SUPPORT_BRIGHTNESS |
|
||||
SUPPORT_TRANSITION |
|
||||
SUPPORT_COLOR |
|
||||
(SUPPORT_WHITE_VALUE if len(self.port) == 4 else 0)
|
||||
)
|
||||
return LightEntityFeature.TRANSITION
|
||||
|
||||
def get_rgbw(self):
|
||||
if not self.is_on:
|
||||
@@ -225,6 +247,7 @@ class MegaRGBW(LightEntity, BaseMegaEntity):
|
||||
for item, value in kwargs.items():
|
||||
setattr(self, f'_{item}', value)
|
||||
_after = self.get_rgbw()
|
||||
self._rgb_color = tuple(_after[:3])
|
||||
if transition is None:
|
||||
transition = self.smooth.total_seconds()
|
||||
ratio = self.calc_speed_ratio(_before, _after)
|
||||
|
||||
@@ -15,5 +15,5 @@
|
||||
"@andvikt"
|
||||
],
|
||||
"issue_tracker": "https://github.com/andvikt/mega_hacs/issues",
|
||||
"version": "v1.1.1"
|
||||
"version": "v1.1.6b1"
|
||||
}
|
||||
@@ -4,9 +4,7 @@ import voluptuous as vol
|
||||
import struct
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
PLATFORM_SCHEMA as SENSOR_SCHEMA,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
DEVICE_CLASS_HUMIDITY, SensorEntity
|
||||
PLATFORM_SCHEMA as SENSOR_SCHEMA, SensorEntity, SensorDeviceClass
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
@@ -40,8 +38,8 @@ UNITS = {
|
||||
HUM: '%'
|
||||
}
|
||||
CLASSES = {
|
||||
TEMP: DEVICE_CLASS_TEMPERATURE,
|
||||
HUM: DEVICE_CLASS_HUMIDITY
|
||||
TEMP: SensorDeviceClass.TEMPERATURE,
|
||||
HUM: SensorDeviceClass.HUMIDITY
|
||||
}
|
||||
# Validation of the user's configuration
|
||||
_ITEM = {
|
||||
@@ -118,15 +116,15 @@ class FilterBadValues(MegaPushEntity, SensorEntity):
|
||||
try:
|
||||
if value \
|
||||
in self.filter_values \
|
||||
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 (
|
||||
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._prev_value is not None
|
||||
and self.filter_scale is not None
|
||||
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':
|
||||
value = self._prev_value
|
||||
else:
|
||||
@@ -231,8 +229,8 @@ class Mega1WSensor(FilterBadValues):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
unit_of_measurement,
|
||||
device_class,
|
||||
unit_of_measurement=None,
|
||||
device_class=None,
|
||||
key=None,
|
||||
*args,
|
||||
**kwargs
|
||||
|
||||
@@ -50,6 +50,10 @@ class PriorityLock(asyncio.Lock):
|
||||
finally:
|
||||
self.release()
|
||||
|
||||
@property
|
||||
def _loop(self):
|
||||
return asyncio.get_event_loop()
|
||||
|
||||
async def acquire(self, priority=0) -> bool:
|
||||
"""Acquire a lock.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user