Skip to content

Commit

Permalink
Duplicate entities on discovery (#18074)
Browse files Browse the repository at this point in the history
* Enhancements for DirecTV media player

Following enhancements have been made:

1. Added debug logging
2. Added ability to change channel using select_source service of the remote platform.
3. State will now show paused if a recorded program is paused, for live TV playing will always be returned.
4. Added the following attributes:
    a. media_position: current position of the media (in seconds)
    b. media_position_updated_at: timestamp when media_position was updated.
   c. source: current source (channel).
   d. media_isbeingrecorded: if current media is being recorded or not.
   e. media_rating: TV/Movie rating of the media
   f. media_recorded: if current media is recorded or live TV
   g. media_starttime: Timestamp media was aired

Reordered properties to follow same order as how they are in __init__.py of remote platform.

* Fixed error and cleaned up few items

Fixed an issue when determining if a program is recorded or not.
Cleaned up some coding.

* Fix issue in checking if DTV device is already configured

If a DTV device was configured before, then discovery would add this device again seperately if the name specified in the configuration is different from the name on the DTV.

This issue is fixed now. Part of the fix also ensure to allow multiple "primary" devices on the network to be discovered.
Further also added debug logging to the setup_platform.

* Further improvements

Some additional improvements related to handling the DATA_DIRECTV in hass.data.

* Fixed flake8 issue

Fixed flake8 issue

* Added available property

Added available property

* Updated to use get_locations()

Replaced doing the request for getLocations with the get_locations() API from DirectPy instead.

* Fix for checking if device is available

Fix for checking if device is available and small update to debug log message.

* Fixed lint issue

Fixed lint issue with unused variable by adding ingore for it as this is for a enumerate

* Updated try/except and removed available

Updated tr/except having the except by the statement we're doing except on.
Removed available, will be a different PR.

* Updated known_devices to be tupples in a set

Updated known_devices to be a tupple in a set, removing loop to determine if client was already added.
  • Loading branch information
ehendrix23 authored and MartinHjelmare committed Nov 5, 2018
1 parent b261c4b commit 561f699
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions homeassistant/components/media_player/directv.py
Expand Up @@ -48,7 +48,7 @@

def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the DirecTV platform."""
known_devices = hass.data.get(DATA_DIRECTV, [])
known_devices = hass.data.get(DATA_DIRECTV, set())
hosts = []

if CONF_HOST in config:
Expand Down Expand Up @@ -89,18 +89,13 @@ def setup_platform(hass, config, add_entities, discovery_info=None):

# Make sure that this device is not already configured
# Comparing based on host (IP) and clientAddr.
device_unknown = True
for device in known_devices:
if host in device and loc["clientAddr"] in device:
device_unknown = False
_LOGGER.debug("Discovered device %s on host %s with "
"client address %s is already "
"configured",
str.title(loc["locationName"]),
host, loc["clientAddr"])
break

if device_unknown:
if (host, loc["clientAddr"]) in known_devices:
_LOGGER.debug("Discovered device %s on host %s with "
"client address %s is already "
"configured",
str.title(loc["locationName"]),
host, loc["clientAddr"])
else:
_LOGGER.debug("Adding discovered device %s with"
" client address %s",
str.title(loc["locationName"]),
Expand All @@ -112,7 +107,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):

for host in hosts:
dtvs.append(DirecTvDevice(*host))
hass.data.setdefault(DATA_DIRECTV, []).append(host)
hass.data.setdefault(DATA_DIRECTV, set()).add((host[1], host[3]))

add_entities(dtvs)

Expand Down

0 comments on commit 561f699

Please sign in to comment.