Compare commits

...

10 Commits

Author SHA1 Message Date
d.dmitriev
5acd5ad692 bump version 2025-02-16 15:40:37 +05:00
d.dmitriev
73ee6c3397 fix config migration 2025-02-16 15:14:33 +05:00
d.dmitriev
ca0f132434 Merge branch 'fix_ha_2025_compatibility' into dev 2025-02-16 14:29:35 +05:00
d.dmitriev
3856088e79 fix HA 2025.1 compatibility; cleanup 2025-02-16 14:20:31 +05:00
Викторов Андрей Германович
40ae6041ae Bump version: 1.1.8b11 → 1.1.8b12 2023-10-17 10:14:37 +03:00
Викторов Андрей Германович
8383c73d0e fix sensors 2023-10-17 10:14:34 +03:00
Викторов Андрей Германович
9d5ea9697d Bump version: 1.1.8b10 → 1.1.8b11 2023-10-17 10:03:52 +03:00
Викторов Андрей Германович
3e5435059d fix sensors 2023-10-16 11:00:01 +03:00
Викторов Андрей Германович
5fc4e1a31e Bump version: 1.1.8b9 → 1.1.8b10 2023-10-15 22:37:34 +03:00
Викторов Андрей Германович
cea3731336 fix sht31 2023-10-15 22:37:30 +03:00
12 changed files with 61 additions and 55 deletions

View File

@@ -1,5 +1,5 @@
[bumpversion] [bumpversion]
current_version = 1.1.8b9 current_version = 1.1.8b14
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

View File

@@ -254,10 +254,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
_hubs[entry.entry_id] = hub _hubs[entry.entry_id] = hub
_subs[entry.entry_id] = entry.add_update_listener(updater) _subs[entry.entry_id] = entry.add_update_listener(updater)
await hub.start() await hub.start()
for platform in PLATFORMS: # for platform in PLATFORMS:
hass.async_create_task( await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
hass.config_entries.async_forward_entry_setup(entry, platform)
)
await hub.updater.async_refresh() await hub.updater.async_refresh()
return True return True
@@ -314,8 +312,7 @@ async def async_migrate_entry(hass, config_entry: ConfigEntry):
await hub.stop() await hub.stop()
new.update(cfg) new.update(cfg)
_LOGGER.debug(f"new config: %s", new) _LOGGER.debug(f"new config: %s", new)
config_entry.data = new hass.config_entries.async_update_entry(config_entry, data=new, version=ConfigFlow.VERSION)
config_entry.version = ConfigFlow.VERSION
_LOGGER.info("Migration to version %s successful", config_entry.version) _LOGGER.info("Migration to version %s successful", config_entry.version)

View File

@@ -17,7 +17,7 @@ from homeassistant.const import (
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.template import Template from homeassistant.helpers.template import Template
from .const import EVENT_BINARY_SENSOR, DOMAIN, CONF_CUSTOM, CONF_SKIP, CONF_INVERT, CONF_RESPONSE_TEMPLATE from .const import DOMAIN, CONF_CUSTOM, CONF_SKIP, CONF_INVERT
from .entities import MegaPushEntity from .entities import MegaPushEntity
from .hub import MegaD from .hub import MegaD
from .tools import int_ignore from .tools import int_ignore

View File

@@ -130,7 +130,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
cfg = dict(self.config_entry.data) cfg = dict(self.config_entry.data)
cfg.update(user_input) cfg.update(user_input)
cfg["new_naming"] = new_naming cfg["new_naming"] = new_naming
self.config_entry.data = cfg self.hass.config_entries.async_update_entry(entry=self.config_entry, data=cfg)
await get_hub(self.hass, cfg) await get_hub(self.hass, cfg)
if reload: if reload:

View File

@@ -1,6 +1,7 @@
"""Constants for the mega integration.""" """Constants for the mega integration."""
import re import re
from itertools import permutations from itertools import permutations
from homeassistant.const import Platform
DOMAIN = "mega" DOMAIN = "mega"
CONF_MEGA_ID = "mega_id" CONF_MEGA_ID = "mega_id"
@@ -53,10 +54,10 @@ CONF_FILTER_HIGH = 'filter_high'
CONF_1WBUS = '1wbus' CONF_1WBUS = '1wbus'
CONF_ADDR = 'addr' CONF_ADDR = 'addr'
PLATFORMS = [ PLATFORMS = [
"light", Platform.LIGHT,
"switch", Platform.SWITCH,
"binary_sensor", Platform.BINARY_SENSOR,
"sensor", Platform.SENSOR,
] ]
EVENT_BINARY_SENSOR = f'{DOMAIN}.sensor' EVENT_BINARY_SENSOR = f'{DOMAIN}.sensor'
EVENT_BINARY = f'{DOMAIN}.binary' EVENT_BINARY = f'{DOMAIN}.binary'

View File

@@ -16,7 +16,6 @@ from .const import (
DOMAIN, DOMAIN,
CONF_CUSTOM, CONF_CUSTOM,
CONF_INVERT, CONF_INVERT,
EVENT_BINARY_SENSOR,
LONG, LONG,
LONG_RELEASE, LONG_RELEASE,
RELEASE, RELEASE,

View File

@@ -10,7 +10,7 @@ from aiohttp.web_response import Response
from homeassistant.helpers.template import Template from homeassistant.helpers.template import Template
from homeassistant.components.http import HomeAssistantView from homeassistant.components.http import HomeAssistantView
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from .const import EVENT_BINARY_SENSOR, DOMAIN, CONF_RESPONSE_TEMPLATE from .const import EVENT_BINARY_SENSOR, CONF_RESPONSE_TEMPLATE
from .tools import make_ints from .tools import make_ints
from . import hub as h from . import hub as h

View File

@@ -12,16 +12,15 @@ from bs4 import BeautifulSoup
from homeassistant.components.sensor import SensorDeviceClass from homeassistant.components.sensor import SensorDeviceClass
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TEMP_CELSIUS, PERCENTAGE, LIGHT_LUX from homeassistant.const import PERCENTAGE, LIGHT_LUX, UnitOfTemperature
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from .config_parser import parse_config, DS2413, MCP230, MCP230_OUT, MCP230_IN, PCA9685 from .config_parser import parse_config, DS2413, MCP230, PCA9685
from .const import ( from .const import (
TEMP, TEMP,
HUM, HUM,
PRESS, PRESS,
LUX, LUX,
PATT_SPLIT,
DOMAIN, DOMAIN,
CONF_HTTP, CONF_HTTP,
EVENT_BINARY_SENSOR, EVENT_BINARY_SENSOR,
@@ -29,7 +28,6 @@ from .const import (
CONF_FORCE_D, CONF_FORCE_D,
CONF_DEF_RESPONSE, CONF_DEF_RESPONSE,
PATT_FW, PATT_FW,
CONF_FORCE_I2C_SCAN,
REMOVE_CONFIG, REMOVE_CONFIG,
) )
from .entities import set_events_off, BaseMegaEntity, MegaOutPort, safe_int, safe_float from .entities import set_events_off, BaseMegaEntity, MegaOutPort, safe_int, safe_float
@@ -42,7 +40,7 @@ HUM_PATT = re.compile(r"hum:([01234567890\.]+)")
PRESS_PATT = re.compile(r"press:([01234567890\.]+)") PRESS_PATT = re.compile(r"press:([01234567890\.]+)")
LUX_PATT = re.compile(r"lux:([01234567890\.]+)") LUX_PATT = re.compile(r"lux:([01234567890\.]+)")
PATTERNS = {TEMP: TEMP_PATT, HUM: HUM_PATT, PRESS: PRESS_PATT, LUX: LUX_PATT} PATTERNS = {TEMP: TEMP_PATT, HUM: HUM_PATT, PRESS: PRESS_PATT, LUX: LUX_PATT}
UNITS = {TEMP: TEMP_CELSIUS, HUM: PERCENTAGE, PRESS: "mmHg", LUX: LIGHT_LUX} UNITS = {TEMP: UnitOfTemperature.CELSIUS, HUM: PERCENTAGE, PRESS: "mmHg", LUX: LIGHT_LUX}
CLASSES = { CLASSES = {
TEMP: SensorDeviceClass.TEMPERATURE, TEMP: SensorDeviceClass.TEMPERATURE,
HUM: SensorDeviceClass.HUMIDITY, HUM: SensorDeviceClass.HUMIDITY,
@@ -489,6 +487,7 @@ class MegaD:
:param params: параметры url :param params: параметры url
:return: :return:
""" """
params = params.copy()
pt = params.get("pt") pt = params.get("pt")
i2c_dev = params.get("i2c_dev", None) i2c_dev = params.get("i2c_dev", None)
@@ -504,7 +503,7 @@ class MegaD:
# инициализация сенсора # инициализация сенсора
await self.request(**__params) await self.request(**__params)
await asyncio.sleep(0.1) await asyncio.sleep(0.1)
self.sht31inited |= pt self.sht31inited.add(pt)
delay = None delay = None
idx: int = params.pop("idx", None) idx: int = params.pop("idx", None)
pt: int = params.get("pt", None) pt: int = params.get("pt", None)
@@ -519,11 +518,14 @@ class MegaD:
elif idx is not None and idx > 0: elif idx is not None and idx > 0:
v: str = self.values.get(f"chache_{pt}") v: str = self.values.get(f"chache_{pt}")
if idx is not None: if idx is not None:
v = safe_float(v.split("/")[idx]) vv = v.split("/")
ret = {_params: v} if len(vv) == 3:
v = vv[idx]
else:
v: None
ret = {_params: safe_float(v)}
except Exception: except Exception:
self.lg.exception(f"while getting i2c {params=}") self.lg.exception(f"while getting i2c {params=}")
except asyncio.TimeoutError:
return return
self.lg.debug("i2c response: %s", ret) self.lg.debug("i2c response: %s", ret)
if delay: if delay:
@@ -687,7 +689,7 @@ class MegaD:
cfg.pop(x, None) cfg.pop(x, None)
cfg.update(new) cfg.update(new)
self.lg.debug(f"new config: %s", cfg) self.lg.debug(f"new config: %s", cfg)
self.config.data = cfg self.hass.config_entries.async_update_entry(self.config, data=cfg)
if reload_entry: if reload_entry:
await self.hass.config_entries.async_reload(self.config.entry_id) await self.hass.config_entries.async_reload(self.config.entry_id)
return cfg return cfg

View File

@@ -7,9 +7,9 @@ from homeassistant.components.sensor import SensorDeviceClass
from homeassistant.const import ( from homeassistant.const import (
PERCENTAGE, PERCENTAGE,
LIGHT_LUX, LIGHT_LUX,
TEMP_CELSIUS,
CONCENTRATION_PARTS_PER_MILLION, CONCENTRATION_PARTS_PER_MILLION,
PRESSURE_BAR, UnitOfTemperature,
UnitOfPressure
) )
from collections import namedtuple from collections import namedtuple
@@ -101,48 +101,48 @@ class Request:
i2c_classes = { i2c_classes = {
"htu21d": [ "htu21d": [
DeviceType(SensorDeviceClass.HUMIDITY, PERCENTAGE, None), DeviceType(SensorDeviceClass.HUMIDITY, PERCENTAGE, None),
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None), DeviceType(SensorDeviceClass.TEMPERATURE, UnitOfTemperature.CELSIUS, None),
], ],
"sht31": [ "sht31": [
DeviceType(SensorDeviceClass.HUMIDITY, PERCENTAGE, None, delay=0.1), DeviceType(SensorDeviceClass.HUMIDITY, PERCENTAGE, None, delay=0.1),
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None), DeviceType(SensorDeviceClass.TEMPERATURE, UnitOfTemperature.CELSIUS, None),
], ],
"max44009": [DeviceType(SensorDeviceClass.ILLUMINANCE, LIGHT_LUX, None)], "max44009": [DeviceType(SensorDeviceClass.ILLUMINANCE, LIGHT_LUX, None)],
"bh1750": [DeviceType(SensorDeviceClass.ILLUMINANCE, LIGHT_LUX, None)], "bh1750": [DeviceType(SensorDeviceClass.ILLUMINANCE, LIGHT_LUX, None)],
"tsl2591": [DeviceType(SensorDeviceClass.ILLUMINANCE, LIGHT_LUX, None)], "tsl2591": [DeviceType(SensorDeviceClass.ILLUMINANCE, LIGHT_LUX, None)],
"bmp180": [ "bmp180": [
DeviceType(SensorDeviceClass.PRESSURE, PRESSURE_BAR, None), DeviceType(SensorDeviceClass.PRESSURE, UnitOfPressure.BAR, None),
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None), DeviceType(SensorDeviceClass.TEMPERATURE, UnitOfTemperature.CELSIUS, None),
], ],
"bmx280": [ "bmx280": [
DeviceType(SensorDeviceClass.PRESSURE, PRESSURE_BAR, None), DeviceType(SensorDeviceClass.PRESSURE, UnitOfPressure.BAR, None),
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None), DeviceType(SensorDeviceClass.TEMPERATURE, UnitOfTemperature.CELSIUS, None),
DeviceType(SensorDeviceClass.HUMIDITY, PERCENTAGE, None), DeviceType(SensorDeviceClass.HUMIDITY, PERCENTAGE, None),
], ],
"dps368": [ "dps368": [
DeviceType(SensorDeviceClass.PRESSURE, PRESSURE_BAR, None), DeviceType(SensorDeviceClass.PRESSURE, UnitOfPressure.BAR, None),
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None), DeviceType(SensorDeviceClass.TEMPERATURE, UnitOfTemperature.CELSIUS, None),
], ],
"mlx90614": [ "mlx90614": [
Skip, Skip,
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, "temp"), DeviceType(SensorDeviceClass.TEMPERATURE, UnitOfTemperature.CELSIUS, "temp"),
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, "object"), DeviceType(SensorDeviceClass.TEMPERATURE, UnitOfTemperature.CELSIUS, "object"),
], ],
"ptsensor": [ "ptsensor": [
Skip, Skip,
Request(delay=3), # запрос на измерение Request(delay=3), # запрос на измерение
DeviceType(SensorDeviceClass.PRESSURE, PRESSURE_BAR, None), DeviceType(SensorDeviceClass.PRESSURE, UnitOfPressure.BAR, None),
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None), DeviceType(SensorDeviceClass.TEMPERATURE, UnitOfTemperature.CELSIUS, None),
], ],
"mcp9600": [ "mcp9600": [
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None), # термопара DeviceType(SensorDeviceClass.TEMPERATURE, UnitOfTemperature.CELSIUS, None), # термопара
DeviceType( DeviceType(
SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None SensorDeviceClass.TEMPERATURE, UnitOfTemperature.CELSIUS, None
), # сенсор встроенный в микросхему ), # сенсор встроенный в микросхему
], ],
"t67xx": [DeviceType(SensorDeviceClass.CO2, CONCENTRATION_PARTS_PER_MILLION, None)], "t67xx": [DeviceType(SensorDeviceClass.CO2, CONCENTRATION_PARTS_PER_MILLION, None)],
"tmp117": [ "tmp117": [
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None), DeviceType(SensorDeviceClass.TEMPERATURE, UnitOfTemperature.CELSIUS, None),
], ],
"ads1115": [ "ads1115": [
DeviceType(None, None, "ch0"), DeviceType(None, None, "ch0"),
@@ -172,7 +172,7 @@ i2c_classes = {
i2c_par=0, i2c_par=0,
idx=0, idx=0,
), ),
DeviceType(SensorDeviceClass.TEMPERATURE, TEMP_CELSIUS, None, i2c_par=0, idx=1), DeviceType(SensorDeviceClass.TEMPERATURE, UnitOfTemperature.CELSIUS, None, i2c_par=0, idx=1),
DeviceType(SensorDeviceClass.HUMIDITY, PERCENTAGE, None, i2c_par=0, idx=2), DeviceType(SensorDeviceClass.HUMIDITY, PERCENTAGE, None, i2c_par=0, idx=2),
], ],
} }

View File

@@ -3,7 +3,6 @@ from __future__ import annotations
import asyncio import asyncio
import logging import logging
import typing
from datetime import timedelta, datetime from datetime import timedelta, datetime
from functools import partial from functools import partial
@@ -13,13 +12,9 @@ import time
from homeassistant.components.light import ( from homeassistant.components.light import (
PLATFORM_SCHEMA as LIGHT_SCHEMA, PLATFORM_SCHEMA as LIGHT_SCHEMA,
SUPPORT_BRIGHTNESS,
LightEntity, LightEntity,
SUPPORT_TRANSITION,
SUPPORT_COLOR,
ColorMode, ColorMode,
LightEntityFeature, LightEntityFeature
# SUPPORT_WHITE_VALUE
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
@@ -124,10 +119,21 @@ async def async_setup_entry(
class MegaLight(MegaOutPort, LightEntity): class MegaLight(MegaOutPort, LightEntity):
@property @property
def supported_features(self): def supported_features(self):
return (SUPPORT_BRIGHTNESS if self.dimmer else 0) | ( return LightEntityFeature.TRANSITION if self.dimmer else LightEntityFeature(0)
SUPPORT_TRANSITION if self.dimmer else 0
)
@property
def supported_color_modes(self):
if self.dimmer:
return {ColorMode.BRIGHTNESS}
else:
return {ColorMode.ONOFF}
@property
def color_mode(self):
if self.dimmer:
return ColorMode.BRIGHTNESS
else:
return ColorMode.ONOFF
class MegaRGBW(LightEntity, BaseMegaEntity): class MegaRGBW(LightEntity, BaseMegaEntity):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):

View File

@@ -12,8 +12,9 @@
"homekit": {}, "homekit": {},
"after_dependencies": ["mqtt"], "after_dependencies": ["mqtt"],
"codeowners": [ "codeowners": [
"@andvikt" "@andvikt",
"@den-dmitriev"
], ],
"issue_tracker": "https://github.com/andvikt/mega_hacs/issues", "issue_tracker": "https://github.com/andvikt/mega_hacs/issues",
"version": "v1.1.8b9" "version": "v1.1.8b14"
} }

View File

@@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
git clone https://github.com/andvikt/mega_hacs.git git clone https://github.com/den-dmitriev/mega_hacs.git
mkdir custom_components mkdir custom_components
cp mega_hacs/custom_components/mega custom_components/mega cp mega_hacs/custom_components/mega custom_components/mega
rm -fR mega_hacs rm -fR mega_hacs