|
10 | 10 |
|
11 | 11 | from homeassistant.helpers.network import get_url
|
12 | 12 | import homeassistant.helpers.config_validation as cv
|
| 13 | +from homeassistant.helpers.typing import HomeAssistantType |
13 | 14 | import voluptuous as vol
|
14 | 15 |
|
15 | 16 | DOMAIN = "plex_assistant"
|
@@ -42,6 +43,16 @@ class PA:
|
42 | 43 | client_sensor = []
|
43 | 44 | alias_names = []
|
44 | 45 | client_update = True
|
| 46 | + zeroconf = None |
| 47 | + |
| 48 | + |
| 49 | +async def get_zeroconf_singleton(hass: HomeAssistantType): |
| 50 | + try: |
| 51 | + from homeassistant.components.zeroconf import async_get_instance |
| 52 | + PA.zeroconf = await async_get_instance(hass) |
| 53 | + except: |
| 54 | + from zeroconf import Zeroconf |
| 55 | + PA.zeroconf = Zeroconf() |
45 | 56 |
|
46 | 57 |
|
47 | 58 | def setup(hass, config):
|
@@ -75,7 +86,9 @@ def setup(hass, config):
|
75 | 86 | if tts_error and not os.path.exists(directory):
|
76 | 87 | os.makedirs(directory, mode=0o777)
|
77 | 88 |
|
78 |
| - get_chromecasts(blocking=False, callback=cc_callback) |
| 89 | + get_chromecasts(blocking=False, callback=cc_callback, |
| 90 | + zeroconf_instance=PA.zeroconf) |
| 91 | + |
79 | 92 | PA.server = PlexServer(base_url, token)
|
80 | 93 | PA.plex = PA.server.library
|
81 | 94 | PA.lib = get_libraries(PA.plex)
|
@@ -104,7 +117,8 @@ def handle_input(call):
|
104 | 117 | command_string = call.data.get("command").strip().lower()
|
105 | 118 | _LOGGER.debug("Command: %s", command_string)
|
106 | 119 |
|
107 |
| - get_chromecasts(blocking=False, callback=cc_callback) |
| 120 | + get_chromecasts(blocking=False, callback=cc_callback, |
| 121 | + zeroconf_instance=PA.zeroconf) |
108 | 122 |
|
109 | 123 | PA.clients = PA.server.clients()
|
110 | 124 | PA.client_names = [client.title for client in PA.clients]
|
|
0 commit comments