Compare commits

..

12 Commits

Author SHA1 Message Date
Викторов Андрей Германович
c8b3cb60de Bump version: 1.1.4 → 1.1.5b0 2023-08-03 16:13:14 +03:00
Викторов Андрей Германович
bd550442d4 fix #151 2023-08-03 16:12:35 +03:00
andvikt
8903628b36 fix #120 2023-06-13 18:09:01 +03:00
andvikt
e1a6637f28 fix #145 2023-06-13 17:47:19 +03:00
andvikt
a346cb3fd7 fix #138 2023-06-13 17:39:49 +03:00
andvikt
d6ef137e75 fix #127 2023-06-13 17:15:42 +03:00
andvikt
d7180c0477 Bump version: 1.1.4b0 → 1.1.4 2022-09-08 12:42:10 +03:00
andvikt
1ceb7e4766 Bump version: 1.1.3 → 1.1.4b0 2022-09-08 12:41:56 +03:00
andvikt
ef46ac2b2b fix 2022.9 2022-09-08 12:41:42 +03:00
andvikt
e44aef35fb Bump version: 1.1.3b0 → 1.1.3 2022-07-22 10:09:04 +03:00
andvikt
a860ba9822 Bump version: 1.1.2b0 → 1.1.3b0 2022-07-22 10:08:43 +03:00
andvikt
2463b270e5 fix asyncio.lock 2022-07-22 10:08:37 +03:00
9 changed files with 97 additions and 77 deletions

View File

@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.1.2b0
current_version = 1.1.5b0
parse = (?P<major>\d+)(\.(?P<minor>\d+))(\.(?P<patch>\d+))(?P<release>[bf]*)(?P<build>\d*)
commit = True
tag = True

View File

@@ -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]
}

View File

@@ -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:

View File

@@ -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

View File

@@ -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=1.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'),

View File

@@ -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)

View File

@@ -15,5 +15,5 @@
"@andvikt"
],
"issue_tracker": "https://github.com/andvikt/mega_hacs/issues",
"version": "v1.1.2b0"
"version": "v1.1.5b0"
}

View File

@@ -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

View File

@@ -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.