1 """Huawei LTE buttons."""
3 from __future__
import annotations
7 from huawei_lte_api.enums.device
import ControlModeEnum
12 ButtonEntityDescription,
19 from .const
import DOMAIN
20 from .entity
import HuaweiLteBaseEntityWithDevice
22 _LOGGER = logging.getLogger(__name__)
27 config_entry: ConfigEntry,
28 async_add_entities: entity_platform.AddEntitiesCallback,
30 """Set up Huawei LTE buttons."""
31 router = hass.data[DOMAIN].routers[config_entry.entry_id]
40 """Huawei LTE button base class."""
44 """Return unique ID for entity within a router."""
45 return f
"button-{self.entity_description.key}"
48 """Update is not necessary for button entities."""
52 if self.router.suspended:
54 "%s: ignored, integration suspended", self.entity_description.key
57 result = self._press()
58 _LOGGER.debug(
"%s: %s", self.entity_description.key, result)
61 """Invoke low level action of button press."""
62 raise NotImplementedError
65 BUTTON_KEY_CLEAR_TRAFFIC_STATISTICS =
"clear_traffic_statistics"
69 """Huawei LTE clear traffic statistics button."""
72 key=BUTTON_KEY_CLEAR_TRAFFIC_STATISTICS,
73 name=
"Clear traffic statistics",
74 entity_category=EntityCategory.CONFIG,
78 """Call clear traffic statistics endpoint."""
79 return self.
routerrouter.client.monitoring.set_clear_traffic()
82 BUTTON_KEY_RESTART =
"restart"
86 """Huawei LTE restart button."""
89 key=BUTTON_KEY_RESTART,
91 device_class=ButtonDeviceClass.RESTART,
92 entity_category=EntityCategory.CONFIG,
96 """Call restart endpoint."""
97 return self.
routerrouter.client.device.set_control(ControlModeEnum.REBOOT)