Skip to content

Commit

Permalink
Fixing Pyright
Browse files Browse the repository at this point in the history
  • Loading branch information
YpNo committed Oct 6, 2024
1 parent 2dc5f81 commit 943ff16
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 31 deletions.
45 changes: 18 additions & 27 deletions mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@
from aiostream import stream # pylint: disable=import-error
from decouple import config # pylint: disable=import-error

MQTT_BROKER = config("MQTT_BROKER", cast=str, default="localhost")
MQTT_PORT = config("MQTT_PORT", cast=int, default=1883)
MQTT_USER = config("MQTT_USER", cast=str, default="arlo")
MQTT_PASS = config("MQTT_PASS", cast=str, default="arlo")
MQTT_RECONNECT_INTERVAL = config("MQTT_RECONNECT_INTERVAL", default=5)
MQTT_TOPIC_PICTURE = config("MQTT_TOPIC_PICTURE", default="arlo/picture/{name}")
# MQTT_TOPIC_LOCATION = config('MQTT_TOPIC_LOCATION', default='arlo/location')
MQTT_TOPIC_CONTROL = config("MQTT_TOPIC_CONTROL", default="arlo/control/{name}")
MQTT_TOPIC_STATUS = config("MQTT_TOPIC_STATUS", default="arlo/status/{name}")
MQTT_TOPIC_MOTION = config("MQTT_TOPIC_MOTION", default="arlo/motion/{name}")
# For PyRight issue which doesn't work with decouple
env_params = {
"MQTT_BROKER": config("MQTT_BROKER", cast=str, default="localhost"),
"MQTT_PORT": config("MQTT_PORT", cast=int, default=1883),
"MQTT_USER": config("MQTT_USER", cast=str, default="arlo"),
"MQTT_PASS": config("MQTT_PASS", cast=str, default="arlo"),
"MQTT_RECONNECT_INTERVAL": config("MQTT_RECONNECT_INTERVAL", default=5),
"MQTT_TOPIC_PICTURE": config("MQTT_TOPIC_PICTURE", default="arlo/picture/{name}"),
"MQTT_TOPIC_CONTROL": config("MQTT_TOPIC_CONTROL", default="arlo/control/{name}"),
"MQTT_TOPIC_STATUS": config("MQTT_TOPIC_STATUS", default="arlo/status/{name}"),
"MQTT_TOPIC_MOTION": config("MQTT_TOPIC_MOTION", default="arlo/motion/{name}"),
}

DEBUG = config("DEBUG", default=False, cast=bool)

Expand All @@ -29,19 +31,6 @@
)
logger = logging.getLogger(__name__)

# For PyRight issue which doesn't work with decouple
env_params = {
"MQTT_BROKER": MQTT_BROKER,
"MQTT_PORT": MQTT_PORT,
"MQTT_USER": MQTT_USER,
"MQTT_PASS": MQTT_PASS,
"MQTT_RECONNECT_INTERVAL": MQTT_RECONNECT_INTERVAL,
"MQTT_TOPIC_PICTURE": MQTT_TOPIC_PICTURE,
"MQTT_TOPIC_CONTROL": MQTT_TOPIC_CONTROL,
"MQTT_TOPIC_STATUS": MQTT_TOPIC_STATUS,
"MQTT_TOPIC_MOTION": MQTT_TOPIC_MOTION,
}


async def mqtt_client(cameras, bases):
"""
Expand Down Expand Up @@ -77,7 +66,7 @@ async def pic_streamer(client, cameras):
async for name, data in streamer:
timestamp = str(time.time()).replace(".", "")
await client.publish(
MQTT_TOPIC_PICTURE.format(name=name),
env_params["MQTT_TOPIC_PICTURE"].format(name=name),

Check failure on line 69 in mqtt.py

View workflow job for this annotation

GitHub Actions / linting

Cannot access attribute "format" for class "bool"   Attribute "format" is unknown (reportAttributeAccessIssue)
payload=json.dumps(
{
"filename": f"{timestamp} {name}.jpg",
Expand All @@ -95,7 +84,8 @@ async def device_status(client, devices):
async with statuses.stream() as streamer:
async for name, status in streamer:
await client.publish(
MQTT_TOPIC_STATUS.format(name=name), payload=json.dumps(status)
env_params["MQTT_TOPIC_STATUS"].format(name=name),

Check failure on line 87 in mqtt.py

View workflow job for this annotation

GitHub Actions / linting

Cannot access attribute "format" for class "bool"   Attribute "format" is unknown (reportAttributeAccessIssue)
payload=json.dumps(status),
)


Expand All @@ -107,15 +97,16 @@ async def motion_stream(client, cameras):
async with motion_states.stream() as streamer:
async for name, motion in streamer:
await client.publish(
MQTT_TOPIC_MOTION.format(name=name), payload=json.dumps(motion)
env_params["MQTT_TOPIC_MOTION"].format(name=name),

Check failure on line 100 in mqtt.py

View workflow job for this annotation

GitHub Actions / linting

Cannot access attribute "format" for class "bool"   Attribute "format" is unknown (reportAttributeAccessIssue)
payload=json.dumps(motion),
)


async def mqtt_reader(client, devices):
"""
Subscribe to control topics, and pass messages to individual cameras
"""
devs = {MQTT_TOPIC_CONTROL.format(name=d.name): d for d in devices}
devs = {env_params["MQTT_TOPIC_CONTROL"].format(name=d.name): d for d in devices}

Check failure on line 109 in mqtt.py

View workflow job for this annotation

GitHub Actions / linting

Cannot access attribute "format" for class "bool"   Attribute "format" is unknown (reportAttributeAccessIssue)
async with client.messages() as messages:
for name, _ in devs.items():
await client.subscribe(name)
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.black]
line-length = 88
target-version = ['py311']
target-version = ['py312']
include = '\.pyi?$'
extend-exclude = '''
/(
Expand All @@ -17,8 +17,9 @@ extend-exclude = '''
'''

[project]
name = "black"
description = "The uncompromising code formatter."
name = "arlo-camera-streamer"
dynamic = ["version"]
description = "Continuous streaming for Arlo cameras"
license = { text = "MIT" }
requires-python = ">=3.9"
authors = [
Expand All @@ -28,7 +29,6 @@ keywords = [
"automation",
"formatter",
"pyfmt",
"yapf",
]
classifiers = [
"Development Status :: 5 - Production/Stable",
Expand Down

0 comments on commit 943ff16

Please sign in to comment.