Compare commits

..

4 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
12 changed files with 53 additions and 51 deletions

View File

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

View File

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

View File

@@ -130,7 +130,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
cfg = dict(self.config_entry.data)
cfg.update(user_input)
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)
if reload:

View File

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

View File

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

View File

@@ -10,7 +10,7 @@ from aiohttp.web_response import Response
from homeassistant.helpers.template import Template
from homeassistant.components.http import HomeAssistantView
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 . import hub as h

View File

@@ -12,16 +12,15 @@ from bs4 import BeautifulSoup
from homeassistant.components.sensor import SensorDeviceClass
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.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 (
TEMP,
HUM,
PRESS,
LUX,
PATT_SPLIT,
DOMAIN,
CONF_HTTP,
EVENT_BINARY_SENSOR,
@@ -29,7 +28,6 @@ from .const import (
CONF_FORCE_D,
CONF_DEF_RESPONSE,
PATT_FW,
CONF_FORCE_I2C_SCAN,
REMOVE_CONFIG,
)
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\.]+)")
LUX_PATT = re.compile(r"lux:([01234567890\.]+)")
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 = {
TEMP: SensorDeviceClass.TEMPERATURE,
HUM: SensorDeviceClass.HUMIDITY,
@@ -691,7 +689,7 @@ class MegaD:
cfg.pop(x, None)
cfg.update(new)
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:
await self.hass.config_entries.async_reload(self.config.entry_id)
return cfg

View File

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

View File

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

View File

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

View File

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