-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #169 from g4bri3lDev/main
Added service calls for common tag actions
- Loading branch information
Showing
4 changed files
with
140 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"services": { | ||
"dlimg": { | ||
"service": "mdi:download" | ||
}, | ||
"lines4": { | ||
"service": "mdi:text-long" | ||
}, | ||
"lines5": { | ||
"service": "mdi:text-long" | ||
}, | ||
"drawcustom": { | ||
"service": "mdi:code-braces-box" | ||
}, | ||
"setled": { | ||
"service": "mdi:wall-sconce-flat-variant" | ||
}, | ||
"clear_pending": { | ||
"service": "mdi:delete" | ||
}, | ||
"force_refresh": { | ||
"service": "mdi:refresh" | ||
}, | ||
"reboot_tag": { | ||
"service": "mdi:restart" | ||
}, | ||
"scan_channels": { | ||
"service": "mdi:signal" | ||
}, | ||
"reboot_ap": { | ||
"service": "mdi:restart" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,50 @@ | ||
from __future__ import annotations | ||
from .const import DOMAIN | ||
import requests | ||
import logging | ||
from homeassistant.core import HomeAssistant | ||
|
||
_LOGGER: Final = logging.getLogger(__name__) | ||
|
||
def get_image_folder(hass): | ||
"""Return the folder where images are stored.""" | ||
return hass.config.path("www/open_epaper_link") | ||
|
||
def get_image_path(hass, entity_id): | ||
"""Return the path to the image for a specific tag.""" | ||
return hass.config.path("www/open_epaper_link/open_epaper_link."+ str(entity_id).lower() + ".jpg") | ||
return hass.config.path("www/open_epaper_link/open_epaper_link."+ str(entity_id).lower() + ".jpg") | ||
async def send_tag_cmd(hass: HomeAssistant, entity_id: str, cmd: str) -> bool: | ||
"""Send a command to an ESL Tag.""" | ||
ip = hass.states.get(DOMAIN + ".ip").state | ||
mac = entity_id.split(".")[1].upper() | ||
url = f"http://{ip}/tag_cmd" | ||
|
||
data = { | ||
'mac': mac, | ||
'cmd': cmd | ||
} | ||
|
||
try: | ||
result = await hass.async_add_executor_job(lambda : requests.post(url, data=data)) | ||
if result.status_code == 200: | ||
_LOGGER.info("Sent %s command to %s", cmd, entity_id) | ||
else: | ||
_LOGGER.error("Failed to send %s command to %s", cmd, entity_id) | ||
except Exception as e: | ||
_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 |