custom-components / pyscript

Pyscript adds rich Python scripting to HASS
Apache License 2.0
873 stars 46 forks source link

Sending group notifications raise errors #600

Open DrissiReda opened 5 months ago

DrissiReda commented 5 months ago

Hello,

First I want to thank you for this great component, it has been very helpful in setting up complex logic in my home assistant server and it's incredibly useful for a beginner.

However, I 'm running into issues sending notifications to groups:

The current code works for a single mobile, but gives an error when using a group instead, bear in mind send a notification to the group via the notify service works without an issue:

# Attempt 1
service.call("notify", notify_target, title=f"Title", message=f"something", data={"image": "    /local/snp.jpg", "tag": "random-id"})
# Attempt 2
notify.group_name(title=f"Title", message=f"something", data={"image": "    /local/snp.jpg", "tag": "random-id"})

Both these function calls return the same output. Also I'd rather go with the first anyway because the targeted group is received via a variable.

Error sending notification to https://mobile-apps.home-assistant.io/api/sendPush/android/v1: 
ContentTypeError(RequestInfo(url=URL('https://mobile-apps.home-assistant.io/api/sendPush/android/v1'), method='POST', headers=<CIMultiDictProxy('Host': 'mobile-apps.home-assistant.io', 'User-Agent': 'HomeAssistant/2024.4.3 aiohttp/3.9.4 Python/3.12', 'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate, br', 'Content-Length': '647', 'Content-Type': 'application/json')>, 
real_url=URL('https://mobile-apps.home-assistant.io/api/sendPush/android/v1')), (), 

message='Attempt to decode JSON with unexpected mimetype: text/html; charset=utf-8', 

headers=<CIMultiDictProxy('Connection': 'keep-alive', 'Content-Length': '1613', 'Content-Type': 'text/html; charset=UTF-8', 'Referrer-Policy': 'no-referrer', 'Accept-Ranges': 'bytes', 'Date': 'Mon, 22 Apr 2024 06:28:19 GMT', 'X-Served-By': 'cache-mrs10547-MRS', 'X-Cache': 'MISS', 'X-Cache-Hits': '0', 'X-Timer': 'S1713767300.597143,VS0,VE16', 'alt-svc': 'h3=":443";ma=86400,h3-29=":443";ma=86400,h3-27=":443";ma=86400')>)

Any ideas what I'm doing wrong to receive the error:

Attempt to decode JSON with unexpected mimetype: text/html; charset=utf-8