Esempio n. 1
0
async def async_setup_entry(
    hass: HomeAssistantType,
    entry: ConfigEntry,
    async_add_entities: Callable[[List, bool], None],
) -> bool:
    """Set up the DirecTV config entry."""
    locations = hass.data[DOMAIN][entry.entry_id][DATA_LOCATIONS]
    version_info = hass.data[DOMAIN][entry.entry_id][DATA_VERSION_INFO]
    entities = []

    for loc in locations["locations"]:
        if "locationName" not in loc or "clientAddr" not in loc:
            continue

        if loc["clientAddr"] != "0":
            dtv = DIRECTV(
                entry.data[CONF_HOST],
                DEFAULT_PORT,
                loc["clientAddr"],
                determine_state=False,
            )
        else:
            dtv = hass.data[DOMAIN][entry.entry_id][DATA_CLIENT]

        entities.append(
            DirecTvDevice(
                str.title(loc["locationName"]),
                loc["clientAddr"],
                dtv,
                version_info,
            ))

    async_add_entities(entities, True)
Esempio n. 2
0
 def __init__(self, name, host, port, device):
     """Initialize the device."""
     from DirectPy import DIRECTV
     self.dtv = DIRECTV(host, port, device)
     self._name = name
     self._is_standby = True
     self._current = None
Esempio n. 3
0
def get_dtv_data(
    hass: HomeAssistant, host: str, port: int = DEFAULT_PORT, client_addr: str = "0"
) -> dict:
    """Retrieve a DIRECTV instance, locations list, and version info for the receiver device."""
    dtv = DIRECTV(host, port, client_addr, determine_state=False)
    locations = dtv.get_locations()
    version_info = dtv.get_version()

    return {
        DATA_CLIENT: dtv,
        DATA_LOCATIONS: locations,
        DATA_VERSION_INFO: version_info,
    }
Esempio n. 4
0
def validate_input(data: Dict) -> Dict:
    """Validate the user input allows us to connect.

    Data has the keys from DATA_SCHEMA with values provided by the user.
    """
    dtv = DIRECTV(data["host"], DEFAULT_PORT, determine_state=False)
    version_info = dtv.get_version()

    return {
        "title": data["host"],
        "host": data["host"],
        "receiver_id": "".join(version_info["receiverId"].split()),
    }
Esempio n. 5
0
    def __init__(self, name, host, port, device):
        """Initialize the device."""
        from DirectPy import DIRECTV
        self.dtv = DIRECTV(host, port, device)
        self._name = name
        self._is_standby = True
        self._current = None
        self._last_update = None
        self._paused = None
        self._last_position = None
        self._is_recorded = None
        self._assumed_state = None

        _LOGGER.debug("Created DirecTV device for %s", self._name)
Esempio n. 6
0
    def __init__(self, name, host, port, device):
        """Initialize the device."""
        from DirectPy import DIRECTV
        self.dtv = DIRECTV(host, port, device)
        self._name = name
        self._is_standby = True
        self._current = None
        self._last_update = None
        self._paused = None
        self._last_position = None
        self._is_recorded = None
        self._is_client = device != '0'
        self._assumed_state = None
        self._available = False
        self._first_error_timestamp = None

        if self._is_client:
            _LOGGER.debug("Created DirecTV client %s for device %s",
                          self._name, device)
        else:
            _LOGGER.debug("Created DirecTV device for %s", self._name)
Esempio n. 7
0
def setup_platform(hass, config, add_entities, discovery_info=None):
    """Set up the DirecTV platform."""
    known_devices = hass.data.get(DATA_DIRECTV, set())
    hosts = []

    if CONF_HOST in config:
        _LOGGER.debug(
            "Adding configured device %s with client address %s ",
            config.get(CONF_NAME),
            config.get(CONF_DEVICE),
        )
        hosts.append([
            config.get(CONF_NAME),
            config.get(CONF_HOST),
            config.get(CONF_PORT),
            config.get(CONF_DEVICE),
        ])

    elif discovery_info:
        host = discovery_info.get("host")
        name = "DirecTV_{}".format(discovery_info.get("serial", ""))

        # Attempt to discover additional RVU units
        _LOGGER.debug("Doing discovery of DirecTV devices on %s", host)

        from DirectPy import DIRECTV

        dtv = DIRECTV(host, DEFAULT_PORT)
        try:
            resp = dtv.get_locations()
        except requests.exceptions.RequestException as ex:
            # Bail out and just go forward with uPnP data
            # Make sure that this device is not already configured
            # Comparing based on host (IP) and clientAddr.
            _LOGGER.debug("Request exception %s trying to get locations", ex)
            resp = {
                "locations": [{
                    "locationName": name,
                    "clientAddr": DEFAULT_DEVICE
                }]
            }

        _LOGGER.debug("Known devices: %s", known_devices)
        for loc in resp.get("locations") or []:
            if "locationName" not in loc or "clientAddr" not in loc:
                continue

            # Make sure that this device is not already configured
            # Comparing based on host (IP) and clientAddr.
            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"]),
                    loc["clientAddr"],
                )
                hosts.append([
                    str.title(loc["locationName"]),
                    host,
                    DEFAULT_PORT,
                    loc["clientAddr"],
                ])

    dtvs = []

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

    add_entities(dtvs)