From 81d85ba1ed290ed41fbbe4152826a976d5f70354 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 4 Mar 2021 20:45:42 +0300 Subject: [PATCH] remove crap entities --- custom_components/mega/binary_sensor.py | 2 ++ custom_components/mega/config_flow.py | 6 +++++- custom_components/mega/const.py | 13 ++++++++++++- custom_components/mega/entities.py | 7 +++++++ custom_components/mega/hub.py | 2 +- custom_components/mega/light.py | 2 ++ custom_components/mega/sensor.py | 2 ++ custom_components/mega/switch.py | 2 ++ 8 files changed, 33 insertions(+), 3 deletions(-) diff --git a/custom_components/mega/binary_sensor.py b/custom_components/mega/binary_sensor.py index e8f7bbb..668e69c 100644 --- a/custom_components/mega/binary_sensor.py +++ b/custom_components/mega/binary_sensor.py @@ -57,6 +57,8 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn continue hub.lg.debug(f'add binary_sensor on port %s', port) sensor = MegaBinarySensor(mega=hub, port=port, config_entry=config_entry) + if '<' in sensor.name: + continue devices.append(sensor) async_add_devices(devices) diff --git a/custom_components/mega/config_flow.py b/custom_components/mega/config_flow.py index 3c11b31..b598c32 100644 --- a/custom_components/mega/config_flow.py +++ b/custom_components/mega/config_flow.py @@ -11,7 +11,8 @@ from homeassistant.const import CONF_HOST, CONF_ID, CONF_PASSWORD, CONF_SCAN_INT from homeassistant.core import callback, HomeAssistant from .const import DOMAIN, CONF_PORT_TO_SCAN, CONF_RELOAD, PLATFORMS, CONF_MQTT_INPUTS, \ CONF_NPORTS, CONF_UPDATE_ALL, CONF_POLL_OUTS, CONF_FAKE_RESPONSE, CONF_FORCE_D, \ - CONF_ALLOW_HOSTS, CONF_PROTECTED, CONF_RESTORE_ON_RESTART, CONF_UPDATE_TIME # pylint:disable=unused-import + CONF_ALLOW_HOSTS, CONF_PROTECTED, CONF_RESTORE_ON_RESTART, CONF_UPDATE_TIME, \ + REMOVE_CONFIG # pylint:disable=unused-import from .hub import MegaD from . import exceptions @@ -131,7 +132,10 @@ class OptionsFlowHandler(config_entries.OptionsFlow): cfg = dict(self.config_entry.data) for x in PLATFORMS: cfg.pop(x, None) + for x in REMOVE_CONFIG: + cfg.pop(x, default=None) cfg.update(new) + cfg['new_naming'] = new_naming return self.async_create_entry( title='', diff --git a/custom_components/mega/const.py b/custom_components/mega/const.py index b3e0822..b8430bd 100644 --- a/custom_components/mega/const.py +++ b/custom_components/mega/const.py @@ -55,4 +55,15 @@ LUX = 'lux' SINGLE_CLICK = 'single' DOUBLE_CLICK = 'double' -PATT_FW = re.compile(r'fw:\s(.+)\)') \ No newline at end of file +PATT_FW = re.compile(r'fw:\s(.+)\)') + +REMOVE_CONFIG = [ + 'extenders', + 'ext_in', + 'ext_acts', + 'i2c_sensors', + 'binary_sensor', + 'light', + 'i2c', + 'sensor', +] \ No newline at end of file diff --git a/custom_components/mega/entities.py b/custom_components/mega/entities.py index 81d21b8..5b64559 100644 --- a/custom_components/mega/entities.py +++ b/custom_components/mega/entities.py @@ -69,6 +69,13 @@ class BaseMegaEntity(CoordinatorEntity, RestoreEntity): if self.http_cmd == 'ds2413': self.mega.ds2413_ports |= {self.port} + @property + def enabled(self): + if '<' in self.name: + return False + else: + return super().enabled + @property def customize(self): if self.hass is None: diff --git a/custom_components/mega/hub.py b/custom_components/mega/hub.py index ceef7c8..b83f3f3 100644 --- a/custom_components/mega/hub.py +++ b/custom_components/mega/hub.py @@ -557,7 +557,7 @@ class MegaD: ret['i2c_sensors'] = i2c_sensors = [] async for port, cfg in self.scan_ports(nports): _cust = self.customize.get(port) - if not isinstance(_customise, dict): + if not isinstance(_cust, dict): _cust = {} if cfg.pty == "0": ret['binary_sensor'][port].append({}) diff --git a/custom_components/mega/light.py b/custom_components/mega/light.py index d4f45ab..4ceca20 100644 --- a/custom_components/mega/light.py +++ b/custom_components/mega/light.py @@ -69,6 +69,8 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn for data in cfg: hub.lg.debug(f'add light on port %s with data %s', port, data) light = MegaLight(mega=hub, port=port, config_entry=config_entry, **data) + if '<' in light.name: + continue devices.append(light) async_add_devices(devices) diff --git a/custom_components/mega/sensor.py b/custom_components/mega/sensor.py index 715b2fa..69f86f8 100644 --- a/custom_components/mega/sensor.py +++ b/custom_components/mega/sensor.py @@ -94,6 +94,8 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn config_entry=config_entry, **data, ) + if '<' in sensor.name: + continue devices.append(sensor) async_add_devices(devices) diff --git a/custom_components/mega/switch.py b/custom_components/mega/switch.py index 36f0884..6065379 100644 --- a/custom_components/mega/switch.py +++ b/custom_components/mega/switch.py @@ -58,6 +58,8 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn for data in cfg: hub.lg.debug(f'add switch on port %s with data %s', port, data) light = MegaSwitch(mega=hub, port=port, config_entry=config_entry, **data) + if '<' in light.name: + continue devices.append(light) async_add_devices(devices)