mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Update praw to 6.4.0 (#27324)
* Update praw to 6.4.0 * Update requirements_test_all.txt * Fix docstrings * Update tests
This commit is contained in:
parent
2747f08385
commit
7e862e4d92
@ -3,7 +3,7 @@
|
|||||||
"name": "Reddit",
|
"name": "Reddit",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/reddit",
|
"documentation": "https://www.home-assistant.io/integrations/reddit",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"praw==6.3.1"
|
"praw==6.4.0"
|
||||||
],
|
],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"codeowners": []
|
"codeowners": []
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import praw
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||||
@ -51,8 +52,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the Reddit sensor platform."""
|
"""Set up the Reddit sensor platform."""
|
||||||
import praw
|
|
||||||
|
|
||||||
subreddits = config[CONF_SUBREDDITS]
|
subreddits = config[CONF_SUBREDDITS]
|
||||||
user_agent = "{}_home_assistant_sensor".format(config[CONF_USERNAME])
|
user_agent = "{}_home_assistant_sensor".format(config[CONF_USERNAME])
|
||||||
limit = config[CONF_MAXIMUM]
|
limit = config[CONF_MAXIMUM]
|
||||||
@ -117,8 +116,6 @@ class RedditSensor(Entity):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update data from Reddit API."""
|
"""Update data from Reddit API."""
|
||||||
import praw
|
|
||||||
|
|
||||||
self._subreddit_data = []
|
self._subreddit_data = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -990,7 +990,7 @@ pocketcasts==0.1
|
|||||||
postnl_api==1.0.2
|
postnl_api==1.0.2
|
||||||
|
|
||||||
# homeassistant.components.reddit
|
# homeassistant.components.reddit
|
||||||
praw==6.3.1
|
praw==6.4.0
|
||||||
|
|
||||||
# homeassistant.components.islamic_prayer_times
|
# homeassistant.components.islamic_prayer_times
|
||||||
prayer_times_calculator==0.0.3
|
prayer_times_calculator==0.0.3
|
||||||
|
@ -354,7 +354,7 @@ plexwebsocket==0.0.1
|
|||||||
pmsensor==0.4
|
pmsensor==0.4
|
||||||
|
|
||||||
# homeassistant.components.reddit
|
# homeassistant.components.reddit
|
||||||
praw==6.3.1
|
praw==6.4.0
|
||||||
|
|
||||||
# homeassistant.components.islamic_prayer_times
|
# homeassistant.components.islamic_prayer_times
|
||||||
prayer_times_calculator==0.0.3
|
prayer_times_calculator==0.0.3
|
||||||
|
@ -3,6 +3,7 @@ import copy
|
|||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from homeassistant.components.reddit import sensor as reddit_sensor
|
||||||
from homeassistant.components.reddit.sensor import (
|
from homeassistant.components.reddit.sensor import (
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
ATTR_SUBREDDIT,
|
ATTR_SUBREDDIT,
|
||||||
@ -98,7 +99,7 @@ MOCK_RESULTS_LENGTH = len(MOCK_RESULTS["results"])
|
|||||||
|
|
||||||
|
|
||||||
class MockPraw:
|
class MockPraw:
|
||||||
"""Mock class for tmdbsimple library."""
|
"""Mock class for Reddit library."""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@ -112,7 +113,7 @@ class MockPraw:
|
|||||||
self._data = MOCK_RESULTS
|
self._data = MOCK_RESULTS
|
||||||
|
|
||||||
def subreddit(self, subreddit: str):
|
def subreddit(self, subreddit: str):
|
||||||
"""Return an instance of a sunbreddit."""
|
"""Return an instance of a subreddit."""
|
||||||
return MockSubreddit(subreddit, self._data)
|
return MockSubreddit(subreddit, self._data)
|
||||||
|
|
||||||
|
|
||||||
@ -160,7 +161,8 @@ class TestRedditSetup(unittest.TestCase):
|
|||||||
@MockDependency("praw")
|
@MockDependency("praw")
|
||||||
@patch("praw.Reddit", new=MockPraw)
|
@patch("praw.Reddit", new=MockPraw)
|
||||||
def test_setup_with_valid_config(self, mock_praw):
|
def test_setup_with_valid_config(self, mock_praw):
|
||||||
"""Test the platform setup with movie configuration."""
|
"""Test the platform setup with Reddit configuration."""
|
||||||
|
with patch.object(reddit_sensor, "praw", mock_praw):
|
||||||
setup_component(self.hass, "sensor", VALID_CONFIG)
|
setup_component(self.hass, "sensor", VALID_CONFIG)
|
||||||
|
|
||||||
state = self.hass.states.get("sensor.reddit_worldnews")
|
state = self.hass.states.get("sensor.reddit_worldnews")
|
||||||
@ -186,6 +188,6 @@ class TestRedditSetup(unittest.TestCase):
|
|||||||
@MockDependency("praw")
|
@MockDependency("praw")
|
||||||
@patch("praw.Reddit", new=MockPraw)
|
@patch("praw.Reddit", new=MockPraw)
|
||||||
def test_setup_with_invalid_config(self, mock_praw):
|
def test_setup_with_invalid_config(self, mock_praw):
|
||||||
"""Test the platform setup with invalid movie configuration."""
|
"""Test the platform setup with invalid Reddit configuration."""
|
||||||
setup_component(self.hass, "sensor", INVALID_SORT_BY_CONFIG)
|
setup_component(self.hass, "sensor", INVALID_SORT_BY_CONFIG)
|
||||||
assert not self.hass.states.get("sensor.reddit_worldnews")
|
assert not self.hass.states.get("sensor.reddit_worldnews")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user