forked from platypush/platypush
Replaced warnings.warn
with logging.warnings
.
I couldn't find an easy and reliable way of routing `warnings.warn` to `logging`. Closes: #281
This commit is contained in:
parent
87a902bfa3
commit
17b6b02986
6 changed files with 37 additions and 45 deletions
15
CHANGELOG.md
15
CHANGELOG.md
|
@ -1,13 +1,22 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
- [[#281](https://git.platypush.tech/platypush/platypush/issues/281)]
|
||||||
|
replaced `warnings.warn` with `logging.warning`, as there is no easy and
|
||||||
|
reliable way of routing `warnings.warn` to `logging`.
|
||||||
|
|
||||||
## [1.1.0] - 2024-06-06
|
## [1.1.0] - 2024-06-06
|
||||||
|
|
||||||
- [#405] Fixed timezone/timestamp rendering issues for `calendar.ical` events.
|
- [[#405](https://git.platypush.tech/platypush/platypush/issues/405)] Fixed
|
||||||
- [#403] Included inherited actions in plugins docs.
|
timezone/timestamp rendering issues for `calendar.ical` events.
|
||||||
|
- [[#403]((https://git.platypush.tech/platypush/platypush/issues/403))]
|
||||||
|
Included inherited actions in plugins docs.
|
||||||
|
|
||||||
## [1.0.7] - 2024-06-02
|
## [1.0.7] - 2024-06-02
|
||||||
|
|
||||||
- [#384] Added `assistant.openai` and `tts.openai` plugins.
|
- [[#384]((https://git.platypush.tech/platypush/platypush/issues/384))] Added
|
||||||
|
`assistant.openai` and `tts.openai` plugins.
|
||||||
|
|
||||||
## [1.0.6] - 2024-06-01
|
## [1.0.6] - 2024-06-01
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
import warnings
|
|
||||||
|
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
@ -168,11 +167,7 @@ class RunnablePlugin(Plugin):
|
||||||
self._thread: Optional[threading.Thread] = None
|
self._thread: Optional[threading.Thread] = None
|
||||||
|
|
||||||
if kwargs.get('poll_seconds') is not None:
|
if kwargs.get('poll_seconds') is not None:
|
||||||
warnings.warn(
|
self.logger.warning('poll_seconds is deprecated, use poll_interval instead')
|
||||||
'poll_seconds is deprecated, use poll_interval instead',
|
|
||||||
DeprecationWarning,
|
|
||||||
stacklevel=2,
|
|
||||||
)
|
|
||||||
|
|
||||||
if self.poll_interval is None:
|
if self.poll_interval is None:
|
||||||
self.poll_interval = kwargs['poll_seconds']
|
self.poll_interval = kwargs['poll_seconds']
|
||||||
|
|
|
@ -17,8 +17,6 @@ from typing import (
|
||||||
Set,
|
Set,
|
||||||
Union,
|
Union,
|
||||||
)
|
)
|
||||||
import warnings
|
|
||||||
|
|
||||||
from platypush.config import Config
|
from platypush.config import Config
|
||||||
from platypush.context import get_bus
|
from platypush.context import get_bus
|
||||||
from platypush.entities import Entity, LightEntityManager
|
from platypush.entities import Entity, LightEntityManager
|
||||||
|
@ -86,11 +84,7 @@ class LightHuePlugin(RunnablePlugin, LightEntityManager):
|
||||||
|
|
||||||
poll_seconds = kwargs.pop('poll_seconds', None)
|
poll_seconds = kwargs.pop('poll_seconds', None)
|
||||||
if poll_seconds is not None:
|
if poll_seconds is not None:
|
||||||
warnings.warn(
|
self.logger.warning('poll_seconds is deprecated, use poll_interval instead')
|
||||||
'poll_seconds is deprecated, use poll_interval instead',
|
|
||||||
DeprecationWarning,
|
|
||||||
stacklevel=2,
|
|
||||||
)
|
|
||||||
|
|
||||||
if poll_interval is None:
|
if poll_interval is None:
|
||||||
poll_interval = poll_seconds
|
poll_interval = poll_seconds
|
||||||
|
@ -1156,12 +1150,16 @@ class LightHuePlugin(RunnablePlugin, LightEntityManager):
|
||||||
temperature=entity.get('state', {}).get('ct'),
|
temperature=entity.get('state', {}).get('ct'),
|
||||||
colormode=entity.get('colormode'),
|
colormode=entity.get('colormode'),
|
||||||
reachable=entity.get('state', {}).get('reachable'),
|
reachable=entity.get('state', {}).get('reachable'),
|
||||||
x=entity['state']['xy'][0]
|
x=(
|
||||||
if entity.get('state', {}).get('xy')
|
entity['state']['xy'][0]
|
||||||
else None,
|
if entity.get('state', {}).get('xy')
|
||||||
y=entity['state']['xy'][1]
|
else None
|
||||||
if entity.get('state', {}).get('xy')
|
),
|
||||||
else None,
|
y=(
|
||||||
|
entity['state']['xy'][1]
|
||||||
|
if entity.get('state', {}).get('xy')
|
||||||
|
else None
|
||||||
|
),
|
||||||
effect=entity.get('state', {}).get('effect'),
|
effect=entity.get('state', {}).get('effect'),
|
||||||
**(
|
**(
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from collections.abc import Collection
|
from collections.abc import Collection
|
||||||
import time
|
import time
|
||||||
from typing import List, Optional, Union
|
from typing import List, Optional, Union
|
||||||
import warnings
|
|
||||||
|
|
||||||
from platypush.context import get_bus
|
from platypush.context import get_bus
|
||||||
from platypush.entities.distance import DistanceSensor
|
from platypush.entities.distance import DistanceSensor
|
||||||
|
@ -45,10 +44,8 @@ class SensorHcsr04Plugin(GpioPlugin, SensorPlugin):
|
||||||
|
|
||||||
measurement_interval = kwargs.pop('measurement_interval', None)
|
measurement_interval = kwargs.pop('measurement_interval', None)
|
||||||
if measurement_interval is not None:
|
if measurement_interval is not None:
|
||||||
warnings.warn(
|
self.logger.warning(
|
||||||
'measurement_interval is deprecated, use poll_interval instead',
|
'measurement_interval is deprecated, use poll_interval instead',
|
||||||
DeprecationWarning,
|
|
||||||
stacklevel=2,
|
|
||||||
)
|
)
|
||||||
poll_interval = measurement_interval
|
poll_interval = measurement_interval
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from dataclasses import asdict
|
from dataclasses import asdict
|
||||||
import warnings
|
|
||||||
from typing import Iterable, List, Optional, Union
|
from typing import Iterable, List, Optional, Union
|
||||||
|
|
||||||
from platypush.plugins import RunnablePlugin, action
|
from platypush.plugins import RunnablePlugin, action
|
||||||
|
@ -184,10 +183,8 @@ class SoundPlugin(RunnablePlugin):
|
||||||
blocksize = blocksize or self.output_blocksize
|
blocksize = blocksize or self.output_blocksize
|
||||||
|
|
||||||
if file:
|
if file:
|
||||||
warnings.warn(
|
self.logger.warning(
|
||||||
'file is deprecated, use resource instead',
|
'file is deprecated, use resource instead',
|
||||||
DeprecationWarning,
|
|
||||||
stacklevel=1,
|
|
||||||
)
|
)
|
||||||
if not resource:
|
if not resource:
|
||||||
resource = file
|
resource = file
|
||||||
|
@ -232,10 +229,8 @@ class SoundPlugin(RunnablePlugin):
|
||||||
"""
|
"""
|
||||||
Deprecated alias for :meth:`.record`.
|
Deprecated alias for :meth:`.record`.
|
||||||
"""
|
"""
|
||||||
warnings.warn(
|
self.logger.warning(
|
||||||
'sound.stream_recording is deprecated, use sound.record instead',
|
'sound.stream_recording is deprecated, use sound.record instead',
|
||||||
DeprecationWarning,
|
|
||||||
stacklevel=1,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.record(*args, **kwargs)
|
return self.record(*args, **kwargs)
|
||||||
|
@ -319,10 +314,8 @@ class SoundPlugin(RunnablePlugin):
|
||||||
"""
|
"""
|
||||||
Deprecated alias for :meth:`.record`.
|
Deprecated alias for :meth:`.record`.
|
||||||
"""
|
"""
|
||||||
warnings.warn(
|
self.logger.warning(
|
||||||
'sound.recordplay is deprecated, use sound.record with `play_audio=True` instead',
|
'sound.recordplay is deprecated, use sound.record with `play_audio=True` instead',
|
||||||
DeprecationWarning,
|
|
||||||
stacklevel=1,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
kwargs['play_audio'] = True
|
kwargs['play_audio'] = True
|
||||||
|
@ -398,10 +391,8 @@ class SoundPlugin(RunnablePlugin):
|
||||||
Deprecated alias for :meth:`.status`.
|
Deprecated alias for :meth:`.status`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
warnings.warn(
|
self.logger.warning(
|
||||||
'sound.query_streams is deprecated, use sound.status instead',
|
'sound.query_streams is deprecated, use sound.status instead',
|
||||||
DeprecationWarning,
|
|
||||||
stacklevel=1,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.status()
|
return self.status()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import warnings
|
import logging
|
||||||
|
|
||||||
from marshmallow import Schema, fields, pre_dump, post_dump
|
from marshmallow import Schema, fields, pre_dump, post_dump
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@ from platypush.context import get_plugin
|
||||||
|
|
||||||
from . import MediaArtistSchema, MediaCollectionSchema, MediaVideoSchema
|
from . import MediaArtistSchema, MediaCollectionSchema, MediaVideoSchema
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class JellyfinSchema(Schema):
|
class JellyfinSchema(Schema):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
@ -20,9 +22,10 @@ class JellyfinSchema(Schema):
|
||||||
@post_dump
|
@post_dump
|
||||||
def gen_img_url(self, data: dict, **_) -> dict:
|
def gen_img_url(self, data: dict, **_) -> dict:
|
||||||
if 'image' in self.fields:
|
if 'image' in self.fields:
|
||||||
|
plugin = get_plugin('media.jellyfin')
|
||||||
|
assert plugin, 'The media.jellyfin plugin is not configured'
|
||||||
data['image'] = (
|
data['image'] = (
|
||||||
get_plugin('media.jellyfin').server
|
plugin.server + f'/Items/{data["id"]}' # type: ignore
|
||||||
+ f'/Items/{data["id"]}' # type: ignore
|
|
||||||
'/Images/Primary?fillHeight=333&fillWidth=222&quality=96'
|
'/Images/Primary?fillHeight=333&fillWidth=222&quality=96'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -43,9 +46,8 @@ class JellyfinSchema(Schema):
|
||||||
|
|
||||||
if not video_format:
|
if not video_format:
|
||||||
if not available_containers:
|
if not available_containers:
|
||||||
warnings.warn(
|
logger.warning(
|
||||||
f'The media ID {data["Id"]} has no available video containers',
|
'The media ID %s has no available video containers', data["Id"]
|
||||||
stacklevel=2,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
Loading…
Reference in a new issue