77https://github.com/custom-cards/upcoming-media-card
88
99"""
10- import os .path
11- import logging
1210import json
11+ import logging
12+ import math
13+ import os
14+ import os .path
15+ import re
16+ import time
17+ import xml .etree .ElementTree as ET
18+ from datetime import datetime
19+ from unicodedata import normalize
20+ from urllib .parse import quote
21+
1322import requests
14- import voluptuous as vol
23+
1524import homeassistant .helpers .config_validation as cv
16- from datetime import datetime
25+ import voluptuous as vol
1726from homeassistant .components .sensor import PLATFORM_SCHEMA
1827from homeassistant .const import CONF_HOST , CONF_PORT , CONF_SSL
1928from homeassistant .helpers .entity import Entity
29+ from pytz import timezone , utc
2030
2131__version__ = '0.1.5'
2232
@@ -47,7 +57,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
4757class PlexRecentlyAddedSensor (Entity ):
4858
4959 def __init__ (self , hass , conf ):
50- from pytz import timezone
5160 self .conf_dir = str (hass .config .path ()) + '/'
5261 self ._dir = '/custom-lovelace/upcoming-media-card/images/plex/'
5362 self .img = '{0}{1}{2}{3}{4}.jpg' .format (
@@ -85,7 +94,6 @@ def state(self):
8594
8695 @property
8796 def device_state_attributes (self ):
88- import math
8997 attributes = {}
9098 if self .change_detected :
9199 self .card_json = []
@@ -175,8 +183,6 @@ def device_state_attributes(self):
175183 return attributes
176184
177185 def update (self ):
178- import re
179- import os
180186 plex = requests .Session ()
181187 if not self .cert :
182188 """Default SSL certificate is for plex.tv not our api server"""
@@ -274,7 +280,6 @@ def update(self):
274280
275281def image_url (url_elements , cert_check , img ):
276282 """Plex can resize images with a long & partially % encoded url."""
277- from urllib .parse import quote
278283 ssl , host , local , port , token , self_cert , dl_images = url_elements
279284 if not cert_check and not self_cert :
280285 ssl = ''
@@ -298,8 +303,6 @@ def image_url(url_elements, cert_check, img):
298303
299304def get_server_ip (name , token ):
300305 """With a token and server name we get server's ip, local ip, and port"""
301- import xml .etree .ElementTree as ET
302- from unicodedata import normalize
303306 plex_tv = requests .get (
304307 'https://plex.tv/api/servers.xml?X-Plex-Token=' + token , timeout = 10 )
305308 plex_xml = ET .fromstring (plex_tv .content )
@@ -312,8 +315,6 @@ def get_server_ip(name, token):
312315
313316
314317def days_since (date , tz ):
315- import time
316- from pytz import utc
317318 date = datetime .utcfromtimestamp (date ).isoformat () + 'Z'
318319 date = datetime .strptime (date , '%Y-%m-%dT%H:%M:%SZ' )
319320 date = str (date .replace (tzinfo = utc ).astimezone (tz ))[:10 ]
0 commit comments