8000 Add kodi unique id based on discovery by rytilahti · Pull Request #15093 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add kodi unique id based on discovery #15093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 30, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions homeassistant/components/media_player/kodi.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
if DATA_KODI not in hass.data:
hass.data[DATA_KODI] = dict()

unique_id = None
# Is this a manual configuration?
if discovery_info is None:
name = config.get(CONF_NAME)
Expand All @@ -175,13 +176,24 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
tcp_port = DEFAULT_TCP_PORT
encryption = DEFAULT_PROXY_SSL
websocket = DEFAULT_ENABLE_WEBSOCKET
properties = discovery_info.get('properties')
if properties is not None:
unique_id = properties.get('uuid', None)

# Only add a device once, so discovered devices do not override manual
# config.
ip_addr = socket.gethostbyname(host)
if ip_addr in hass.data[DATA_KODI]:
return

# If we got an unique id, check that it does not exist already.
# This is necessary as netdisco does not deterministally return the same
# advertisement when the service is offered over multiple IP addresses.
if unique_id is not None:
for device in hass.data[DATA_KODI].values():
if device.unique_id == unique_id:
return

entity = KodiDevice(
hass,
name=name,
Expand All @@ -190,7 +202,8 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
password=config.get(CONF_PASSWORD),
turn_on_action=config.get(CONF_TURN_ON_ACTION),
turn_off_action=config.get(CONF_TURN_OFF_ACTION),
timeout=config.get(CONF_TIMEOUT), websocket=websocket)
timeout=config.get(CONF_TIMEOUT), websocket=websocket,
unique_id=unique_id)

hass.data[DATA_KODI][ip_addr] = entity
async_add_devices([entity], update_before_add=True)
Expand Down Expand Up @@ -260,12 +273,14 @@ class KodiDevice(MediaPlayerDevice):
def __init__(self, hass, name, host, port, tcp_port, encryption=False,
username=None, password=None,
turn_on_action=None, turn_off_action=None,
timeout=DEFAULT_TIMEOUT, websocket=True):
timeout=DEFAULT_TIMEOUT, websocket=True,
unique_id=None):
"""Initialize the Kodi device."""
import jsonrpc_async
import jsonrpc_websocket
self.hass = hass
self._name = name
self._unique_id = unique_id

kwargs = {
'timeout': timeout,
Expand Down Expand Up @@ -384,6 +399,11 @@ def _get_players(self):
_LOGGER.debug("Unable to fetch kodi data", exc_info=True)
return None

@property
def unique_id(self):
"""Return the unique id of the device."""
return self._unique_id

@property
def state(self):
"""Return the state of the device."""
Expand Down
0