Skip to content
This repository was archived by the owner on May 26, 2022. It is now read-only.

Commit 2bdb96d

Browse files
committed
use HA zerconf
1 parent 2e6c1ac commit 2bdb96d

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

custom_components/plex_assistant/__init__.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from homeassistant.helpers.network import get_url
1212
import homeassistant.helpers.config_validation as cv
13+
from homeassistant.helpers.typing import HomeAssistantType
1314
import voluptuous as vol
1415

1516
DOMAIN = "plex_assistant"
@@ -42,6 +43,16 @@ class PA:
4243
client_sensor = []
4344
alias_names = []
4445
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()
4556

4657

4758
def setup(hass, config):
@@ -75,7 +86,9 @@ def setup(hass, config):
7586
if tts_error and not os.path.exists(directory):
7687
os.makedirs(directory, mode=0o777)
7788

78-
get_chromecasts(blocking=False, callback=cc_callback)
89+
get_chromecasts(blocking=False, callback=cc_callback,
90+
zeroconf_instance=PA.zeroconf)
91+
7992
PA.server = PlexServer(base_url, token)
8093
PA.plex = PA.server.library
8194
PA.lib = get_libraries(PA.plex)
@@ -104,7 +117,8 @@ def handle_input(call):
104117
command_string = call.data.get("command").strip().lower()
105118
_LOGGER.debug("Command: %s", command_string)
106119

107-
get_chromecasts(blocking=False, callback=cc_callback)
120+
get_chromecasts(blocking=False, callback=cc_callback,
121+
zeroconf_instance=PA.zeroconf)
108122

109123
PA.clients = PA.server.clients()
110124
PA.client_names = [client.title for client in PA.clients]

0 commit comments

Comments
 (0)