Skip to content

Commit b6e7ff5

Browse files
committed
The device name has been corrected, attributes have been added, and the documentation has been updated
1 parent bbe2b73 commit b6e7ff5

File tree

7 files changed

+84
-3
lines changed

7 files changed

+84
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Home Assistant custom component for control Huawei mesh routers over LAN.
3838
- control of the Fast Roaming function (802.11r)
3939
- control of the Target Wake Time (reduce power consumption of Wi-Fi 6 devices in sleep mode)
4040
- port mapping switches
41+
- Internet access time control switches
4142
- reboot buttons
4243
- events for connecting, disconnecting, or moving devices over a mesh network
4344
- automatic detection of available functions
@@ -153,6 +154,7 @@ You can attach one or more tags to each client device in order to be able to use
153154
* Website filtering ([read more](docs/controls.md#website-filtering))
154155
* Guest network ([read more](docs/controls.md#guest-network))
155156
* Port mapping ([read more](docs/controls.md#port-mapping))
157+
* Internet access time ([read more](docs/controls.md#internet-access-time))
156158

157159
### Selects
158160
* Wi-Fi access control mode ([read more](docs/controls.md#wi-fi-access-control-mode))

custom_components/huawei_mesh_router/client/classes.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,16 +472,42 @@ def id(self) -> str:
472472
@property
473473
def name(self) -> str:
474474
"""Return the name of the item."""
475-
parts = [part for part in self.id.split(".") if part]
476-
last_non_empty = parts[-1] if parts else "?"
477-
return f"Time limit rule {last_non_empty}"
475+
device_names = [
476+
item.get("HostName", "device") for item in self._data.get("DeviceNames", [])
477+
]
478+
days = [
479+
active_day.day_of_week.value
480+
for active_day in filter(lambda x: x.is_enabled, self._days.values())
481+
]
482+
483+
device_names_str = (
484+
"for " + ", ".join(device_names)
485+
if len(device_names) > 0
486+
else "for some devices"
487+
)
488+
489+
if len(days) == 7:
490+
days_str = "for every day"
491+
elif days == ["Saturday", "Sunday"]:
492+
days_str = "on weekends"
493+
elif days == ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]:
494+
days_str = "on working days"
495+
else:
496+
days_str = "on " + ", ".join(days)
497+
498+
return f"Time limit rule {device_names_str} {days_str}"
478499

479500
@property
480501
def enabled(self) -> bool:
481502
"""Return the state of the item."""
482503
value = self._data.get("Enable")
483504
return isinstance(value, bool) and value
484505

506+
@property
507+
def devices_mac(self) -> Iterable[MAC_ADDR]:
508+
"""Return the state of the item."""
509+
return [device.get("MACAddress", "no_mac_addr") for device in self._data.get("Devices", [])]
510+
485511
@property
486512
def days(self) -> dict[DayOfWeek, HuaweiTimeControlItemDay]:
487513
"""Return the schedule for each day."""

custom_components/huawei_mesh_router/switch.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,30 @@ def _handle_coordinator_update(self) -> None:
846846
f"{_FUNCTION_DISPLAYED_NAME_TIME_CONTROL}: {self._time_control.name}"
847847
)
848848

849+
for day in self._time_control.days.values():
850+
self._attr_extra_state_attributes[day.day_of_week.value.lower()] = (
851+
{
852+
"is_enabled": day.is_enabled,
853+
"start_time": day.start,
854+
"end_time": day.end,
855+
}
856+
if day.is_enabled
857+
else {"is_enabled": day.is_enabled}
858+
)
859+
860+
if self.coordinator.connected_devices:
861+
device_index = 1
862+
for device_mac in self._time_control.devices_mac:
863+
device: ConnectedDevice = self.coordinator.connected_devices.get(
864+
device_mac
865+
)
866+
if device:
867+
self._attr_extra_state_attributes[f"device_{device_index}"] = {
868+
"mac": device.mac,
869+
"name": device.name,
870+
}
871+
device_index += 1
872+
849873
super()._handle_coordinator_update()
850874

851875
@property

docs/controls.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,35 @@ _Note: these switches are not attached to a specific router device._
153153

154154
_Note: if the port forwarding is removed in the Primary router, the corresponding switch will be removed from the Home Assistant._
155155

156+
### Internet access time
157+
158+
Allows you to enable or disable Internet access time control.
159+
160+
![Access time control switch](images/switch_time_access_control.png)
161+
162+
One switch is created for each forwarded port in the router:
163+
* `switch.<integration_name>_time_control_time_limit_rule_<rule_id>`
164+
165+
__Attention__: The rule identifier is generated by the router. When deleting a rule and creating a new one, the identifier of the new rule will most likely match the identifier of the deleted rule. This should be taken into account when using these switches.
166+
167+
Each switch exposes the following attributes:
168+
169+
| Attribute | Description |
170+
|-------------------------------------|-----------------------------------------------------------------------------------------------------------------|
171+
| `<the name of the day of the week>` | `is_enabled`: Is the filter enabled on that day; `start_time`: Access start time; `end_time`: Access end time. |
172+
| `device_<number>` | `mac`: The MAC address of the device to which the restrictions apply; `name`: The name of the device |
173+
174+
You can configure Internet Access Time Limit in the web interface of your router.
175+
Example address: `http://192.168.3.1/html/index.html#/more/parentcontrol`
176+
177+
![Internet Access Time Limit setup](images/parental_control_access_time.png)
178+
179+
These switches will not be added to Home Assistant if the Primary router does not support access time limits, or this feature is not enabled in [advanced options](../README.md#advanced-options).
180+
181+
_Note: these switches are not attached to a specific router device._
182+
183+
_Note: if the access time limit rule is removed in the Primary router, the corresponding switch will be removed from the Home Assistant._
184+
156185
### Guest network
157186

158187
Allows you to enable or disable the guest Wi-Fi network.

docs/images/options_2.png

2.52 KB
Loading
121 KB
Loading
41 KB
Loading

0 commit comments

Comments
 (0)