Skip to content

Commit ccee581

Browse files
committed
Update
- removed is_local because it was used incorrectly/was unnecessary - added verify_ssl to config so the request will accept all certificates
1 parent 461ee5b commit ccee581

File tree

7 files changed

+29
-26
lines changed

7 files changed

+29
-26
lines changed

custom_components/plex_recently_added/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
CONF_SECTION_LIBRARIES,
1818
CONF_EXCLUDE_KEYWORDS,
1919
CONF_ON_DECK,
20-
CONF_LOCAL
20+
CONF_VERIFY_SSL
2121
)
2222

2323

@@ -46,7 +46,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
4646
config_entry.data.get(CONF_SECTION_TYPES, []),
4747
config_entry.data.get(CONF_SECTION_LIBRARIES, []),
4848
config_entry.data.get(CONF_EXCLUDE_KEYWORDS, []),
49-
config_entry.data[CONF_LOCAL],
49+
config_entry.data[CONF_VERIFY_SSL],
5050
)
5151
except FailedToLogin as err:
5252
raise ConfigEntryNotReady("Failed to Log-in") from err

custom_components/plex_recently_added/config_flow.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
CONF_SECTION_LIBRARIES,
3030
CONF_EXCLUDE_KEYWORDS,
3131
CONF_ON_DECK,
32-
CONF_LOCAL
32+
CONF_VERIFY_SSL
3333
)
3434

3535
from .helpers import setup_client
@@ -44,7 +44,7 @@
4444
vol.Required(CONF_PORT, default=32400): vol.All(vol.Coerce(int), vol.Range(min=0)),
4545
vol.Required(CONF_API_KEY): vol.All(str),
4646
vol.Optional(CONF_SSL, default=False): vol.All(bool),
47-
vol.Optional(CONF_LOCAL, default=False): vol.All(bool),
47+
vol.Optional(CONF_VERIFY_SSL, default=True): vol.All(bool),
4848
vol.Optional(CONF_MAX, default=5): vol.All(vol.Coerce(int), vol.Range(min=0)),
4949
vol.Optional(CONF_ON_DECK, default=False): vol.All(bool),
5050
vol.Optional(CONF_SECTION_TYPES, default={"movie", "show"}): SelectSelector(SelectSelectorConfig(options=ALL_SECTION_TYPES, mode=SelectSelectorMode.DROPDOWN ,multiple=True)),
@@ -79,7 +79,7 @@ async def async_step_user(
7979
user_input.get(CONF_SECTION_TYPES, []),
8080
user_input.get(CONF_SECTION_LIBRARIES, []),
8181
user_input.get(CONF_EXCLUDE_KEYWORDS, []),
82-
user_input[CONF_LOCAL],
82+
user_input[CONF_VERIFY_SSL],
8383
)
8484
except FailedToLogin as err:
8585
errors = {'base': 'failed_to_login'}

custom_components/plex_recently_added/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
CONF_SECTION_LIBRARIES: Final = 'section_libraries'
1212
CONF_EXCLUDE_KEYWORDS: Final = 'exclude_keywords'
1313
CONF_ON_DECK: Final = 'on_deck'
14-
CONF_LOCAL: Final = 'is_local'
14+
CONF_VERIFY_SSL: Final = 'verify_ssl'
1515

1616

1717
USER_AGENT: Final = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36"

custom_components/plex_recently_added/helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ def setup_client(
1212
section_types: list,
1313
section_libraries: list,
1414
exclude_keywords: list,
15-
is_local: bool,
15+
verify_ssl: bool,
1616
):
17-
client = PlexApi(hass, ssl, token, max, on_deck, host, port, section_types, section_libraries, exclude_keywords, is_local)
17+
client = PlexApi(hass, ssl, token, max, on_deck, host, port, section_types, section_libraries, exclude_keywords, verify_ssl)
1818

1919
client.update()
2020
return client

custom_components/plex_recently_added/plex_api.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from pytz import timezone
22
from xml.etree import ElementTree
33
import requests
4+
from urllib3.exceptions import InsecureRequestWarning
45

56
from homeassistant.core import HomeAssistant
67
from .const import DEFAULT_PARSE_DICT, USER_AGENT, ACCEPTS
@@ -23,7 +24,7 @@ def __init__(
2324
section_types: list,
2425
section_libraries: list,
2526
exclude_keywords: list,
26-
is_local: bool
27+
verify_ssl: bool
2728
):
2829
self._hass = hass
2930
self._ssl = 's' if ssl else ''
@@ -35,28 +36,26 @@ def __init__(
3536
self._section_types = section_types
3637
self._section_libraries = section_libraries
3738
self._exclude_keywords = exclude_keywords
38-
self._is_local = is_local
39+
self._verify_ssl = verify_ssl
3940

4041
def update(self):
41-
if self._is_local:
42-
info_url = 'http{0}://{1}:{2}'.format(
43-
self._ssl,
44-
self._host,
45-
self._port
46-
)
47-
else:
48-
info_url = 'http{0}://{1}'.format(
49-
self._ssl,
50-
self._host,
51-
)
42+
info_url = 'http{0}://{1}:{2}'.format(
43+
self._ssl,
44+
self._host,
45+
self._port
46+
)
5247

5348
""" Getting the server identifier """
49+
if not self._verify_ssl:
50+
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
5451
try:
5552
info_res = requests.get(info_url + "/", headers={
5653
"X-Plex-Token": self._token,
5754
"User-agent": USER_AGENT,
5855
"Accepts": ACCEPTS,
59-
}, timeout=10)
56+
},
57+
verify=self._verify_ssl,
58+
timeout=10)
6059
try:
6160
root = ElementTree.fromstring(info_res.text)
6261
except:
@@ -79,7 +78,9 @@ def update(self):
7978
"X-Plex-Token": self._token,
8079
"User-agent": USER_AGENT,
8180
"Accepts": ACCEPTS,
82-
}, timeout=10)
81+
},
82+
verify=self._verify_ssl,
83+
timeout=10)
8384
try:
8485
root = ElementTree.fromstring(libraries.text)
8586
except:
@@ -100,7 +101,9 @@ def update(self):
100101
"X-Plex-Token": self._token,
101102
"User-agent": USER_AGENT,
102103
"Accepts": ACCEPTS,
103-
}, timeout=10)
104+
},
105+
verify=self._verify_ssl,
106+
timeout=10)
104107
try:
105108
root = ElementTree.fromstring(sub_sec.text)
106109
except:

custom_components/plex_recently_added/strings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"section_types": "Which section types to consider",
1414
"exclude_keywords": "Keyword to be exclude from the sensor",
1515
"section_libraries": "Which libraries to consider",
16-
"is_local": "The server address is local (not using domain)"
16+
"verify_ssl": "Verify SSL"
1717
}
1818
}
1919
},

custom_components/plex_recently_added/translations/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"section_types": "Which section types to consider",
1414
"exclude_keywords": "Keyword to be exclude from the sensor",
1515
"section_libraries": "Which libraries to consider",
16-
"is_local": "The server address is local (not using domain)"
16+
"verify_ssl": "Verify SSL"
1717
}
1818
}
1919
},

0 commit comments

Comments
 (0)