Skip to content

Commit

Permalink
Added advanced options for event entities
Browse files Browse the repository at this point in the history
  • Loading branch information
vmakeev committed Aug 6, 2023
1 parent e92e253 commit fe5ded0
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ By default, Huawei mesh routers use the username `admin`, although it is not dis
### Advanced options

You can perform advanced configuration of the component after adding it.
To do this, click on the gear, and in the tab that opens, click `CONFIGURE`
To do this, click on the intergation, and in the tab that opens, click `CONFIGURE`

![Integration](docs/images/integration.png)

Expand All @@ -84,6 +84,7 @@ Advanced settings include:
| Enabling or disabling [Devices tracking](docs/device-tracking.md#devices-tracking) | Disabled |
| Enabling or disabling [Router-specific zones](docs/device-tracking.md#router-specific-zones) | Disabled |
| Enabling or disabling [Website filtering switches](docs/controls.md#website-filtering) | Disabled |
| Enabling or disabling [Event entities](docs/events.md#event-entities) | Disabled |


![Options 1/2](docs/images/options_1.png)
Expand Down
10 changes: 10 additions & 0 deletions custom_components/huawei_mesh_router/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
DEFAULT_DEVICE_TRACKER_ZONES,
DEFAULT_SCAN_INTERVAL,
DEFAULT_URL_FILTER_SWITCHES,
DEFAULT_EVENT_ENTITIES,
DOMAIN,
OPT_DEVICE_TRACKER,
OPT_DEVICE_TRACKER_ZONES,
OPT_DEVICES_TAGS,
OPT_EVENT_ENTITIES,
OPT_ROUTER_CLIENTS_SENSORS,
OPT_URL_FILTER_SWITCHES,
OPT_WIFI_ACCESS_SWITCHES,
Expand Down Expand Up @@ -48,6 +50,9 @@ def _get_platforms(integration_options: HuaweiIntegrationOptions) -> Iterable[st
if not integration_options.device_tracker:
excluded_platforms.append(Platform.DEVICE_TRACKER)

if not integration_options.event_entities:
excluded_platforms.append(Platform.EVENT)

return filter(lambda item: item not in excluded_platforms, PLATFORMS)


Expand Down Expand Up @@ -165,6 +170,11 @@ async def async_migrate_entry(hass, config_entry: ConfigEntry):
updated_options[OPT_URL_FILTER_SWITCHES] = DEFAULT_URL_FILTER_SWITCHES
config_entry.version = 4

if config_entry.version == 4:
_LOGGER.debug("Migrating to version 5")
updated_options[OPT_EVENT_ENTITIES] = DEFAULT_EVENT_ENTITIES
config_entry.version = 5

hass.config_entries.async_update_entry(
config_entry, data=updated_data, options=updated_options
)
Expand Down
10 changes: 9 additions & 1 deletion custom_components/huawei_mesh_router/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
DEFAULT_DEVICE_TRACKER,
DEFAULT_DEVICE_TRACKER_ZONES,
DEFAULT_DEVICES_TAGS,
DEFAULT_EVENT_ENTITIES,
DEFAULT_HOST,
DEFAULT_NAME,
DEFAULT_PASS,
Expand All @@ -38,6 +39,7 @@
OPT_DEVICE_TRACKER,
OPT_DEVICE_TRACKER_ZONES,
OPT_DEVICES_TAGS,
OPT_EVENT_ENTITIES,
OPT_ROUTER_CLIENTS_SENSORS,
OPT_URL_FILTER_SWITCHES,
OPT_WIFI_ACCESS_SWITCHES,
Expand All @@ -63,7 +65,7 @@ def configured_instances(hass):
class HuaweiControllerConfigFlow(ConfigFlow, domain=DOMAIN):
"""HuaweiControllerConfigFlow class"""

VERSION = 4
VERSION = 5

def __init__(self):
"""Initialize HuaweiControllerConfigFlow."""
Expand Down Expand Up @@ -235,6 +237,12 @@ async def async_step_features_select(self, user_input=None) -> FlowResult:
OPT_URL_FILTER_SWITCHES, DEFAULT_URL_FILTER_SWITCHES
),
): bool,
vol.Required(
OPT_EVENT_ENTITIES,
default=self.options.get(
OPT_EVENT_ENTITIES, DEFAULT_EVENT_ENTITIES
),
): bool,
},
),
)
2 changes: 2 additions & 0 deletions custom_components/huawei_mesh_router/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
OPT_DEVICES_TAGS = "devices_tags"
OPT_DEVICE_TRACKER = "device_tracker"
OPT_DEVICE_TRACKER_ZONES = "device_tracker_zones"
OPT_EVENT_ENTITIES = "event_entities"

DEFAULT_HOST: Final = "192.168.3.1"
DEFAULT_USER: Final = "admin"
Expand All @@ -33,6 +34,7 @@
DEFAULT_DEVICE_TRACKER: Final = False
DEFAULT_DEVICE_TRACKER_ZONES: Final = False
DEFAULT_URL_FILTER_SWITCHES: Final = False
DEFAULT_EVENT_ENTITIES: Final = False

ATTR_MANUFACTURER: Final = "Huawei"
PLATFORMS: Final = [
Expand Down
11 changes: 11 additions & 0 deletions custom_components/huawei_mesh_router/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
DEFAULT_DEVICE_TRACKER_ZONES,
DEFAULT_DEVICES_TAGS,
DEFAULT_ROUTER_CLIENTS_SENSORS,
DEFAULT_EVENT_ENTITIES,
DEFAULT_SCAN_INTERVAL,
DEFAULT_URL_FILTER_SWITCHES,
DEFAULT_WIFI_ACCESS_SWITCHES,
OPT_DEVICE_TRACKER,
OPT_DEVICE_TRACKER_ZONES,
OPT_DEVICES_TAGS,
OPT_EVENT_ENTITIES,
OPT_ROUTER_CLIENTS_SENSORS,
OPT_URL_FILTER_SWITCHES,
OPT_WIFI_ACCESS_SWITCHES,
Expand Down Expand Up @@ -83,3 +85,12 @@ def router_clients_sensors(self) -> bool:
OPT_ROUTER_CLIENTS_SENSORS,
DEFAULT_ROUTER_CLIENTS_SENSORS,
)

@property
def event_entities(self) -> bool:
"""Return option 'event entities' value"""
return get_option(
self._config_entry,
OPT_EVENT_ENTITIES,
DEFAULT_EVENT_ENTITIES,
)
3 changes: 2 additions & 1 deletion custom_components/huawei_mesh_router/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"devices_tags": "Device tags",
"device_tracker": "Devices tracking",
"device_tracker_zones": "Router-specific zones for tracked devices",
"url_filter_switches": "Website filtering switches"
"url_filter_switches": "Website filtering switches",
"event_entities": "Event entities"
},
"title": "Huawei mesh router setup (2\/2)",
"description": "Additional features"
Expand Down
3 changes: 2 additions & 1 deletion custom_components/huawei_mesh_router/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"devices_tags": "Tags do dispositivo",
"device_tracker": "Rastreamento de dispositivos",
"device_tracker_zones": "Zonas específicas do roteador para dispositivos rastreados",
"url_filter_switches": "Interruptores de filtragem de sites"
"url_filter_switches": "Interruptores de filtragem de sites",
"event_entities": "Entidades de eventos"
},
"title": "Configuração do roteador mesh Huawei (2\/2)",
"description": "Características adicionais"
Expand Down
3 changes: 2 additions & 1 deletion custom_components/huawei_mesh_router/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"devices_tags": "Теги клиентских устройств",
"device_tracker": "Отслеживание устройств",
"device_tracker_zones": "Отдельные зоны для роутеров при отслеживании устройств",
"url_filter_switches": "Выключатели фильтров web-сайтов"
"url_filter_switches": "Выключатели фильтров web-сайтов",
"event_entities": "Объекты для событий"
},
"title": "Настройка интеграции mesh маршрутизатора Huawei (2\/2)",
"description": "Расширенная функциональность"
Expand Down
2 changes: 2 additions & 0 deletions docs/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ context:

The integration also supports displaying events as entities.

These entities will not be added if `event entities` are not enabled in [advanced options](../README.md#advanced-options).

Primary router have the following event entities:
* `event.<integration_name>_routers`
* `event.<integration_name>_devices`
Expand Down
Binary file modified docs/images/options_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fe5ded0

Please sign in to comment.