Skip to content

Commit c0215d8

Browse files
committed
Revert imports "cleanup"
1 parent 17fce13 commit c0215d8

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

custom_components/sensor/plex_recently_added.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,16 @@
77
https://github.com/custom-cards/upcoming-media-card
88
99
"""
10-
import json
11-
import logging
12-
import math
13-
import os
1410
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-
11+
import logging
12+
import json
2213
import requests
23-
24-
import homeassistant.helpers.config_validation as cv
2514
import voluptuous as vol
15+
import homeassistant.helpers.config_validation as cv
16+
from datetime import datetime
2617
from homeassistant.components.sensor import PLATFORM_SCHEMA
2718
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_SSL
2819
from homeassistant.helpers.entity import Entity
29-
from pytz import timezone, utc
3020

3121
__version__ = '0.1.5'
3222

@@ -60,6 +50,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
6050
class PlexRecentlyAddedSensor(Entity):
6151

6252
def __init__(self, hass, conf):
53+
from pytz import timezone
6354
self.conf_dir = str(hass.config.path()) + '/'
6455
self._dir = conf.get(CONF_IMG_CACHE)
6556
self.img = '{0}{1}{2}{3}{4}.jpg'.format(
@@ -97,6 +88,7 @@ def state(self):
9788

9889
@property
9990
def device_state_attributes(self):
91+
import math
10092
attributes = {}
10193
if self.change_detected:
10294
self.card_json = []
@@ -186,6 +178,8 @@ def device_state_attributes(self):
186178
return attributes
187179

188180
def update(self):
181+
import re
182+
import os
189183
plex = requests.Session()
190184
if not self.cert:
191185
"""Default SSL certificate is for plex.tv not our api server"""
@@ -283,6 +277,7 @@ def update(self):
283277

284278
def image_url(url_elements, cert_check, img):
285279
"""Plex can resize images with a long & partially % encoded url."""
280+
from urllib.parse import quote
286281
ssl, host, local, port, token, self_cert, dl_images = url_elements
287282
if not cert_check and not self_cert:
288283
ssl = ''
@@ -306,6 +301,8 @@ def image_url(url_elements, cert_check, img):
306301

307302
def get_server_ip(name, token):
308303
"""With a token and server name we get server's ip, local ip, and port"""
304+
import xml.etree.ElementTree as ET
305+
from unicodedata import normalize
309306
plex_tv = requests.get(
310307
'https://plex.tv/api/servers.xml?X-Plex-Token=' + token, timeout=10)
311308
plex_xml = ET.fromstring(plex_tv.content)
@@ -318,6 +315,8 @@ def get_server_ip(name, token):
318315

319316

320317
def days_since(date, tz):
318+
import time
319+
from pytz import utc
321320
date = datetime.utcfromtimestamp(date).isoformat() + 'Z'
322321
date = datetime.strptime(date, '%Y-%m-%dT%H:%M:%SZ')
323322
date = str(date.replace(tzinfo=utc).astimezone(tz))[:10]

0 commit comments

Comments
 (0)