Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
yohaybn authored Dec 29, 2021
1 parent d5857ff commit c5899ac
Show file tree
Hide file tree
Showing 4 changed files with 295 additions and 0 deletions.
9 changes: 9 additions & 0 deletions custom component/ustvgo/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"domain": "ustvgo",
"name": "UsTvGo",
"documentation": "https://github.com/danieldotnl/hass-multiscrape",
"requirements": ["requests", "tqdm"],
"codeowners": ["@yohaybn"],
"version": "0.0.1"
}

192 changes: 192 additions & 0 deletions custom component/ustvgo/sensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
"""Support for ustvgo."""
import asyncio
import datetime
from datetime import datetime, timedelta
import logging
import socket
import urllib
import sys
from xml.parsers.expat import ExpatError
import difflib

import aiohttp
import async_timeout
import voluptuous as vol
import xmltodict

from homeassistant.components.sensor import ENTITY_ID_FORMAT, PLATFORM_SCHEMA
from homeassistant.const import (
CONF_NAME,
CONF_RESOURCE,
CONF_RESOURCE_TEMPLATE,
CONF_SCAN_INTERVAL,

)
from homeassistant.exceptions import PlatformNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity, async_generate_entity_id
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed

_LOGGER = logging.getLogger(__name__)

DEFAULT_METHOD = "GET"
DEFAULT_NAME = "ustvgo"
DEFAULT_VERIFY_SSL = True
DEFAULT_FORCE_UPDATE = False
DEFAULT_TIMEOUT = 10
DEFAULT_SCAN_INTERVAL = timedelta(seconds=30)


CONF_ATTR = "attribute"
CONF_SELECT = "select"
CONF_INDEX = "index"


METHODS = ["POST", "GET", "PUT"]

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL): cv.time_period
}
)

SENSOR_SCHEMA = vol.Schema(
{
vol.Required(CONF_SELECT): cv.template,
vol.Optional(CONF_ATTR): cv.string,
vol.Optional(CONF_INDEX, default=0): cv.positive_int,
vol.Required(CONF_NAME): cv.string,
}
)


async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Multiscrape sensor."""
name = config.get(CONF_NAME)
scan_interval = config.get(CONF_SCAN_INTERVAL)
session = async_get_clientsession(hass)
values = {}
async def async_update_data():
"""Fetch data from API endpoint.
This is the place to pre-process the data to lookup tables
so entities can quickly look up their data.
"""
counter=0
try:
async with async_timeout.timeout(1000):
with open('/config/custom_components/ustvgo/ustvgo_channel_info.txt') as file:
for line in file:
line = line.strip()
if not line or line.startswith('~~'):
continue
line = line.split('|')
name = line[0].strip()
code = line[1].strip()
logo = line[2].strip()
_ent={}
data = {'stream': code}

async with session.post('https://ustvgo.tv/data.php', data=data) as response:
m3u = await response.text()
_ent["m3u"] = m3u
_ent["tvg-id"] = code
_ent["tvg-logo"] = logo
_ent["name"] = f"ustvgo_{name}"
values[name]= _ent
_LOGGER.info("collecting sensor: %s",name)
return values
except Exception:
raise UpdateFailed
coordinator = DataUpdateCoordinator(
hass,
_LOGGER,
name=config.get(CONF_NAME),
update_method=async_update_data,
update_interval=scan_interval,
)
# Fetch initial data so we have data when entities subscribe
await coordinator.async_config_entry_first_refresh()
entities = []
for sensor in values:
entities.append(UstvgoSensor(
hass,
coordinator,
sensor,
sensor,
True,)
)
async_add_entities(entities, True)
class UpdateFailed(Exception):
"""Raised when an update has failed."""


class UstvgoSensor(Entity):
"""Implementation of the Multiscrape sensor."""

def __init__(
self,
hass,
coordinator,
key,
name,
force_update
):
"""Initialize the sensor."""
self._hass = hass
self._coordinator = coordinator
self._key = key
self._name = name
self._state = None
self._force_update = force_update
self._attributes = {}
self.entity_id = async_generate_entity_id(
ENTITY_ID_FORMAT, key, hass=hass
)

@property
def name(self):
"""Return the name of the sensor."""
return self._name

@property
def available(self):
"""Return if entity is available."""
return self._coordinator.last_update_success

@property
def state(self):
"""Return the state of the device."""
# _LOGGER.error("state -info: %s",self._coordinator.data)
# _LOGGER.error("state -_key: %s",self._key)
if self._coordinator.data[self._key] is None:
return "Unavilable"
return self._coordinator.data[self._key]['name']

@property
def force_update(self):
"""Force update."""
return self._force_update

@property
def should_poll(self):
"""No need to poll. Coordinator notifies entity of updates."""
return False

async def async_added_to_hass(self):
"""When entity is added to hass."""
self.async_on_remove(
self._coordinator.async_add_listener(
self.async_write_ha_state
)
)

async def async_update(self):
"""Update the entity. Only used by the generic entity update service."""
await self._coordinator.async_request_refresh()

@property
def extra_state_attributes(self):
"""Return the state attributes."""
return self._coordinator.data[self._key]
94 changes: 94 additions & 0 deletions custom component/ustvgo/ustvgo_channel_info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
ABC | ABC | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/abc-us.png | 9233011874
ACC Network | ACCN | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/acc-network-us.png | 9200017734
AE | AE | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/a-and-e-us.png | 9200004889
AMC | AMC | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/amc-us.png | 9200020107
Animal Planet | Animal | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/animal-planet-us.png | 9233013462
BBCAmerica | BBCAmerica | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/bbc-america-us.png | 9200009303
Big Ten Network | BTN | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/btn-us.png | 9200004533
BET | BET | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/bet-us.png | 9233000226
Boomerang | Boomerang | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/boomerang-us.png | 9233015844
Bravo | Bravo | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/bravo-us.png | 9200020094
C-span | CSPAN | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/c-span-1-us.png | 9233007144
CBS | CBS | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/cbs-logo-white-us.png | 9200018514
CBS Sports Network | CBSSN | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/cbs-sports-network-us.png | 9233015468
Cinemax | Cinemax | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/cinemax-us.png | 9200000143
CMT | CMT | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/cmt-us.png | 9233000169
Cartoon Network | CN | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/cartoon-network-us.png | 9233001926
CNBC | CNBC | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/cnbc-us.png | 9200009145
CNN | CNN | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/cnn-us.png | 9233008130
Comedy Central | Comedy | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/comedy-central-us.png | 9233009509
CW | CW | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/cw-us.png | 9233011398
Destination America | DA | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/destination-america-us.png | 9200014472
Discovery | Discovery | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/discovery-channel-us.png | 9233001914
Disney | Disney | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/disney-channel-us.png | 9200011893
DisneyJr | DisneyJr | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/disney-junior-us.png | 9200016560
DisneyXD | DisneyXD | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/disney-xd-us.png | 9200004852
Do it yourself (DIY) | DIY | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/diy-network-us.png | 9200000664
E! | E | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/e-entertainment-us.png | 9233003794
ESPN | ESPN | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/espn-us.png | 9233007996
ESPN2 | ESPN2 | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/espn-2-us.png | 9200016131
ESPNU | ESPNU | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/espn-u-us.png | 9233011350
ESPNews | ESPNews | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/espnews-us.png | 9200006523
FoodNetwork | FoodNetwork | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/food-network-us.png | 9233005598
FOX | FOX | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/Fox5.png | 9233002271
FoxBusiness | FoxBusiness | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/fox-business-us.png | 9200009124
FoxNews | FoxNews | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/fox-news-us.png | 9233006969
Freeform | Freeform | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/freeform-us.png | 9200000497
Fox Sports 1 (FS1) | FS1 | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/fox-sports-1-us.png | 9233000539
Fox Sports 2 (FS2) | FS2 | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/fox-sports-2-us.png | 9200009884
FX | FX | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/fx-us.png | 9233006959
FX Movie Channel | FXMovie | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/fxm-movie-channel-us.png | 9233013967
FXX | FXX | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/fxx-us.png | 9200014910
Golf Channel | GOLF | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/nbc-golf-channel-us.png | 9200011865
Game Show Network | GSN | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/game-show-network-us.png | 9200019858
Hallmark Channel | Hallmark | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/hallmark-us.png | 9200016034
HBO | HBO | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/hbo-us.png | 9200004886
HGTV | HGTV | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/hgtv-us.png | 9200004467
History | History | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/history-channel-us.png | 9233008002
HLN | HLN | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/hln-us.png | 9233005762
Hallmark Movies & Mysteries | HMM | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/hallmark-movies-and-mysteries-us.png | 9200020115
Investigation Discovery | ID | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/investigation-discovery-us.png | 9200002243
Lifetime | Lifetime | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/lifetime-us.png | 9200000502
Lifetime Movie Network | LifetimeM | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/lifetime-movie-network-us.png | 9200000502
MLB Network | MLB | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/mlb-network-us.png | 9200009223
Motor Trend | MotorTrend | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/motor-trend-us.png | 9233003479
MSNBC | MSNBC | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/msnbc-alt-us.png | 9233006803
MTV | MTV | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/mtv-us.png | 9233015501
National Geographic | NatGEO | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/national-geographic-us.png | 9233009337
Nat Geo Wild | NatGEOWild | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/nat-geo-wild-us.png | 9200004683
NBA TV | NBA | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/nba-tv-us.png | 9200000070
NBC | NBC | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/nbc-logo-2013-us.png | 9233009876
NBC Sports (NBCSN) | NBCSN | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/nbcsn-us.png | 9233000030
NFL Network | NFL | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/nfl-network-us.png | 9200004330
NFL Redzone | NFLRZ | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/nfl-red-zone-us.png | 9233000241
Nickelodeon | Nickelodeon | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/nickelodeon-us.png | 9233011497
Nicktoons | Nicktoons | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/nick-toons-us.png | 9200020469
One America News Network | OAN | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/one-america-news-network-us.png | 9200005058
Oprah Winfrey Network (OWN) | OWN | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/opra-winfrey-network-us.png | 9200004740
Olympic Channel | OLY | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/olympics.png | 9233008939
Oxygen | Oxygen | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/oxygen-us.png | 9200012145
Paramount | Paramount | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/paramount-network-us.png | 9233001931
PBS | PBS | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/pbs-us.png | 9233004141
POP | POP | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/pop-us.png | 9200018304
Science | Science | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/discovery-science-us.png | 9200019847
SEC Network | SECN | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/sec-network-us.png | 9233002484
Showtime | Showtime | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/showtime-us.png | 9233011188
StarZ | StarZ | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/starz-us.png | 9233013809
SundanceTV | SundanceTV | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/sundance-tv-us.png | 9233001687
SYFY | SYFY | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/syfy-us.png | 9200004316
TBS | TBS | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/tbs-us.png | 9233011348
Turner Classic Movies (TCM) | TCM | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/tcm-movies-us.png | 9200017928
Telemundo | Telemundo | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/telemundo-us.png | 9200011857
Tennis Channel | Tennis | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/tennis-channel-us.png | 9200017917
TLC | TLC | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/tlc-us.png | 9200016249
TNT | TNT | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/tnt-us.png | 9233011830
Travel Channel | Travel | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/travel-channel-us.png | 9233000035
truTV | TruTV | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/tru-tv-us.png | 9233015561
TV Land | TVLand | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/tv-land-us.png | 9233005468
The Weather Channel | TWC | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/weather-channel-us.png | 9200016258
Univision | Univision | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/univision-us.png | 9200000867
USA Network | USANetwork | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/US/usa-us.png | 9200009133
VH1 | VH1 | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/vh1-us.png | 9233000037
We TV | WETV | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/we-tv-us.png | 9233003770
WWE Network | WWE | https://i.imgur.com/VJoF3bh.png |
YES Network | YES | https://raw.githubusercontent.com/Theitfixer85/myepg/master/Logos/yes-network-us.png | 9200004247
Binary file added images/lovelace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c5899ac

Please sign in to comment.