-
Notifications
You must be signed in to change notification settings - Fork 58
coroutine was expected error. Service to call http to local webserver to control LG tv prior 2012 #576
Unanswered
amoranvalero
asked this question in
Q&A
-
Hello I am trying to send the power off command to an LG TV prior to 2012 vis http post query.
The code is trigger as a service power_off_async and executed properly (using a tasked coroutine) but I always have an error entry of type TypeError: a coroutine was expected, got None in line 31 at the end of async getSessionid coroutine.
The script:
import sys
import xml.etree.ElementTree as etree
import aiohttp
import asyncio
import platform
headers = {"Content-Type": "application/atom+xml"}
pairCmd = "<?xml version=\"1.0\" encoding=\"utf-8\"?><auth><type>AuthReq</type><value>" \
+ "DDHXTF" + "</value></auth>"
async def getSessionid(csa):
async with aiohttp.ClientSession() as session:
response = await session.post(url="http://192.168.1.143:8080/hdcp/api/auth",
data=pairCmd,
headers=headers)
readout = response.text()
tree = etree.XML(readout)
sessionId = tree.find('session').text
cmdText = "<?xml version=\"1.0\" encoding=\"utf-8\"?><command><session>" + str(sessionId) \
+ "</session><type>HandleKeyInput</type><value>" \
+ str(csa) \
+ "</value></command>"
await session.post(url="http://192.168.1.143:8080/hdcp/api/dtv_wifirc",
data=cmdText,
headers=headers)
@service
def power_off_async():
loop = asyncio.get_running_loop()
task = loop.create_task(getSessionid(8))
await task
I don't understand since the service power_off_async is called and the tv turn off but there is always an error flagged in the error log of HA.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment