Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions custom_components/tronbytassistant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,25 +238,6 @@ def validateid(input_value: str) -> bool:
pattern = r"^[A-Za-z0-9]+$"
return bool(re.match(pattern, input_value))

async def getinstalledapps(deviceid: str, only_pushed: bool = True) -> list[str]:
url = f"{coordinator.base_url}/v0/devices/{deviceid}/installations"
header = {
"Authorization": f"Bearer {coordinator.token}",
"Content-Type": "application/json",
"Accept": "application/json",
}
async with session.get(url, headers=header) as response:
if response.status != 200:
error = await response.text()
_LOGGER.error("%s", error)
raise HomeAssistantError(error)
appids: list[str] = []
data = await response.json()
for item in data["installations"]:
if not only_pushed or item["appID"] == "pushed":
appids.append(item["id"])
return appids

async def request(
method: str,
webhook_url: str,
Expand Down Expand Up @@ -401,18 +382,6 @@ async def pixlet_delete(call: ServiceCall) -> None:
refresh_needed = False
for item in targets:
deviceid = item["id"]

validids = await getinstalledapps(deviceid)
if contentid not in validids:
_LOGGER.error(
"The Content ID you entered is not an installed app on %s. Currently installed apps are: %s",
item["name"],
validids,
)
raise HomeAssistantError(
f"The Content ID you entered is not an installed app on {item['name']}. Currently installed apps are: {validids}"
)

url = f"{coordinator.base_url}/v0/devices/{deviceid}/installations/{contentid}"
await request("DELETE", url, {})
refresh_needed = True
Expand All @@ -434,18 +403,6 @@ async def handle_installation_update(
refresh_needed = False
for item in targets:
deviceid = item["id"]

validids = await getinstalledapps(deviceid, only_pushed=False)
if contentid not in validids:
_LOGGER.error(
"The Content ID you entered is not an installed app on %s. Currently installed apps are: %s",
item["name"],
validids,
)
raise HomeAssistantError(
f"The Content ID you entered is not an installed app on {item['name']}. Currently installed apps are: {validids}"
)

endpoint = f"{coordinator.base_url}/v0/devices/{deviceid}/installations/{contentid}"
await request("PATCH", endpoint, payload)
refresh_needed = True
Expand Down
Loading