Skip to content

Commit 14f4678

Browse files
committed
Clean up imports and run isort
1 parent b4c9e4c commit 14f4678

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

custom_components/sensor/plex_recently_added.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,26 @@
77
https://github.com/custom-cards/upcoming-media-card
88
99
"""
10-
import os.path
11-
import logging
1210
import 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+
1322
import requests
14-
import voluptuous as vol
23+
1524
import homeassistant.helpers.config_validation as cv
16-
from datetime import datetime
25+
import voluptuous as vol
1726
from homeassistant.components.sensor import PLATFORM_SCHEMA
1827
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_SSL
1928
from 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):
4757
class 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

275281
def 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

299304
def 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

314317
def 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

Comments
 (0)