Skip to content

Commit f3d8822

Browse files
authored
Merge pull request #41 from JackJPowell/fix-notify
Correct notification errors
2 parents 2f8c9c0 + f646a14 commit f3d8822

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

custom_components/playstation_network/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
"issue_tracker": "https://github.com/JackJPowell/hass-psn/issues",
1212
"requirements": ["PSNAWP-HA==2.2.2"],
1313
"ssdp": [],
14-
"version": "0.7.3"
14+
"version": "0.7.4"
1515
}

custom_components/playstation_network/notify.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from homeassistant.components.notify import ATTR_TARGET, BaseNotificationService
88
from homeassistant.core import HomeAssistant
99
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
10+
from psnawp_api.core.psnawp_exceptions import PSNAWPNotFound
1011

1112
from .const import DOMAIN, PSN_API
1213

@@ -23,15 +24,16 @@ def get_service(
2324
return None
2425

2526
data = hass.data[DOMAIN][discovery_info.get("entry_id")][PSN_API]
26-
return PsnNotificationService(data)
27+
return PsnNotificationService(data, hass)
2728

2829

2930
class PsnNotificationService(BaseNotificationService):
3031
"""Implement the notification service for the PSN Network."""
3132

32-
def __init__(self, psn) -> None:
33+
def __init__(self, psn, hass) -> None:
3334
"""Initialize the service."""
3435
self.psn = psn
36+
self.hass = hass
3537

3638
async def async_send_message(self, message="", **kwargs):
3739
"""Send a message."""
@@ -42,9 +44,19 @@ async def async_send_message(self, message="", **kwargs):
4244
raise ValueError("Missing required argument: target")
4345

4446
for user in users:
45-
individual = await self.psn.user(online_id=user)
46-
user_list.append(individual)
47-
48-
group = await self.psn.group(users_list=user_list)
49-
response = await group.send_message(message)
47+
try:
48+
individual = await self.hass.async_add_executor_job(
49+
lambda: self.psn.user(online_id=user)
50+
)
51+
user_list.append(individual)
52+
except PSNAWPNotFound as err:
53+
_LOGGER.error("User not found: %s", user)
54+
raise err
55+
56+
group = await self.hass.async_add_executor_job(
57+
lambda: self.psn.group(users_list=user_list)
58+
)
59+
response = await self.hass.async_add_executor_job(
60+
lambda: group.send_message(message)
61+
)
5062
_LOGGER.debug("Send Message Response: %s", response)

0 commit comments

Comments
 (0)