diff --git a/custom_components/mega/binary_sensor.py b/custom_components/mega/binary_sensor.py index a4e3d45..5cf62ff 100644 --- a/custom_components/mega/binary_sensor.py +++ b/custom_components/mega/binary_sensor.py @@ -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 diff --git a/custom_components/mega/const.py b/custom_components/mega/const.py index 3c4b4f5..a06d0f4 100644 --- a/custom_components/mega/const.py +++ b/custom_components/mega/const.py @@ -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' diff --git a/custom_components/mega/entities.py b/custom_components/mega/entities.py index b9d79be..16d03ec 100644 --- a/custom_components/mega/entities.py +++ b/custom_components/mega/entities.py @@ -16,7 +16,6 @@ from .const import ( DOMAIN, CONF_CUSTOM, CONF_INVERT, - EVENT_BINARY_SENSOR, LONG, LONG_RELEASE, RELEASE, diff --git a/custom_components/mega/http.py b/custom_components/mega/http.py index 86d2698..28eef97 100644 --- a/custom_components/mega/http.py +++ b/custom_components/mega/http.py @@ -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 diff --git a/custom_components/mega/hub.py b/custom_components/mega/hub.py index e0c489d..200d87c 100644 --- a/custom_components/mega/hub.py +++ b/custom_components/mega/hub.py @@ -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, diff --git a/custom_components/mega/i2c.py b/custom_components/mega/i2c.py index 74ed705..10e2869 100644 --- a/custom_components/mega/i2c.py +++ b/custom_components/mega/i2c.py @@ -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), ], } diff --git a/custom_components/mega/light.py b/custom_components/mega/light.py index ddd5969..585053f 100644 --- a/custom_components/mega/light.py +++ b/custom_components/mega/light.py @@ -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): diff --git a/custom_components/mega/manifest.json b/custom_components/mega/manifest.json index ed6b204..1e5ea05 100644 --- a/custom_components/mega/manifest.json +++ b/custom_components/mega/manifest.json @@ -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.8b13" } \ No newline at end of file diff --git a/install.sh b/install.sh index b31f408..6f14693 100644 --- a/install.sh +++ b/install.sh @@ -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