Skip to content

Commit

Permalink
Added reboot_ap service call
Browse files Browse the repository at this point in the history
  • Loading branch information
g4bri3lDev committed Sep 22, 2024
1 parent 9d99b5e commit 9fe9b4d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
6 changes: 5 additions & 1 deletion custom_components/open_epaper_link/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pprint
import time

from .util import send_tag_cmd
from .util import send_tag_cmd, reboot_ap

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -135,6 +135,9 @@ async def scan_channels_service(service: ServiceCall)-> None:
for entity_id in entity_ids:
await send_tag_cmd(hass, entity_id,"scan")

async def reboot_ap_service(service: ServiceCall)-> None:
await reboot_ap(hass)

# register the services
hass.services.register(DOMAIN, "dlimg", dlimg)
hass.services.register(DOMAIN, "lines5", lines5service)
Expand All @@ -145,6 +148,7 @@ async def scan_channels_service(service: ServiceCall)-> None:
hass.services.register(DOMAIN, "force_refresh", force_refresh_service)
hass.services.register(DOMAIN, "reboot_tag", reboot_tag_service)
hass.services.register(DOMAIN, "scan_channels", scan_channels_service)
hass.services.register(DOMAIN, "reboot_ap", reboot_ap_service)
# error handling needs to be improved
return True

Expand Down
3 changes: 3 additions & 0 deletions custom_components/open_epaper_link/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
},
"scan_channels": {
"service": "mdi:signal"
},
"reboot_ap": {
"service": "mdi:restart"
}
}
}
5 changes: 4 additions & 1 deletion custom_components/open_epaper_link/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,7 @@ scan_channels:
description: Lets the ESL scan for channels
target:
entity:
domain: open_epaper_link
domain: open_epaper_link
reboot_ap:
name: Reboot AP
description: Reboots the AP
13 changes: 13 additions & 0 deletions custom_components/open_epaper_link/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,17 @@ async def send_tag_cmd(hass: HomeAssistant, entity_id: str, cmd: str) -> bool:
_LOGGER.error("Failed to send %s command to %s: %s", cmd, entity_id, e)
return False

async def reboot_ap(hass: HomeAssistant) -> bool:
"""Reboot the ESL Access Point."""
ip = hass.states.get(DOMAIN + ".ip").state
url = f"http://{ip}/reboot"

try:
result = await hass.async_add_executor_job(lambda : requests.post(url))
if result.status_code == 200:
_LOGGER.info("Rebooted ESL Access Point")
else:
_LOGGER.error("Failed to reboot ESL Access Point")
except Exception as e:
_LOGGER.error("Failed to reboot ESL Access Point: %s", e)
return False

0 comments on commit 9fe9b4d

Please sign in to comment.