Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tests and documentation): Improving documentation/docstring and starting fil test files #2

Merged
merged 14 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
# Add 'root' label to any root file changes
# Quotation marks are required for the leading asterisk
root:
- changed-files:
- any-glob-to-any-file: '*'

# Add 'AnyChange' label to any changes within the entire repository
AnyChange:
- changed-files:
- any-glob-to-any-file: '**'

# Add 'Documentation' label to any change to .md files within the entire repository
Documentation:
- changed-files:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ jobs:
uses: microsoft/[email protected]
with:
python_version: '3.12'
pytest: true
pytest: false
testdir: "tests/"
workdir: "."
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/YpNo/arlo-camera-streamer/python-actions.yml)
![CodeQL](https://github.com/YpNo/arlo-camera-streamer/actions/workflows/github-code-scanning/codeql/badge.svg)
![Docker Image CI](https://github.com/YpNo/arlo-camera-streamer/actions/workflows/docker-image.yml/badge.svg)

# arlo-camera-streamer
[![codecov](https://codecov.io/github/YpNo/arlo-camera-streamer/graph/badge.svg?token=1NMSHP7BLW)](https://codecov.io/github/YpNo/arlo-camera-streamer)

> [!IMPORTANT]
> This is a forked project from [arlo-streamer](https://github.com/kaffetorsk/arlo-streamer) project. Reason : Inactivity

# arlo-camera-streamer

Python script that turns arlo cameras into continuous streams through ffmpeg
This allow arlo cameras to be used in the NVR of your choosing. (e.g. [Frigate](https://frigate.video/))

Expand Down
75 changes: 56 additions & 19 deletions base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,71 @@

class Base(Device):
"""
Attributes
----------
name : str
internal name of the base (not necessarily identical to arlo)
status_interval: int
interval of status messages from generator (seconds)
Class representing an Arlo base station.

Attributes:
name (str): Internal name of the base (not necessarily identical to Arlo).
status_interval (int): Interval of status messages from generator (seconds).
"""

def __init__(self, arlo_base, status_interval):
def __init__(self, arlo_base, status_interval: int):
"""
Initialize the Base instance.

Args:
arlo_base (ArloBase): Arlo base station object.
status_interval (int): Interval of status messages from generator (seconds).
"""
super().__init__(arlo_base, status_interval)
logging.info("Base added: %s", self.name)

# Distributes events to correct handler
async def on_event(self, attr, value):
async def on_event(self, attr: str, value):
"""
Distribute events to the correct handler.

Args:
attr (str): Attribute name.
value: Attribute value.
"""
match attr:
case "activeMode":
self._state_event.set()
self.state_event.set()
logging.info("%s mode: %s", self.name, value)
case _:
pass

def get_status(self):
def get_status(self) -> dict:
"""
Get the status of the base station.

Returns:
dict: Status information including mode and siren state.
"""
return {"mode": self._arlo.mode, "siren": self._arlo.siren_state}

async def mqtt_control(self, payload):
async def mqtt_control(self, payload: str):
"""
Handles incoming MQTT commands
Handle incoming MQTT commands.

Args:
payload (str): MQTT payload.
"""
handlers = {"mode": self.set_mode, "siren": self.set_siren}

try:
payload = json.loads(payload)
for k, v in payload.items():
for k, v in payload.items(): # pyright: ignore [reportAttributeAccessIssue]
if k in handlers:
self.event_loop.run_in_executor(None, handlers[k], v)
self._event_loop.run_in_executor(None, handlers[k], v)
except Exception:
logging.warning("%s: Invalid data for MQTT control", self.name)

def set_mode(self, mode):
""" "
Sets mode of Base Station
def set_mode(self, mode: str):
"""
Set the mode of the base station.

Args:
mode (str): Mode to set.
"""
try:
mode = mode.lower()
Expand All @@ -59,7 +83,10 @@ def set_mode(self, mode):

def set_siren(self, state):
"""
Sets siren (on/off/on with specified duration and volume)
Set the siren state (on/off/on with specified duration and volume).

Args:
state (str or dict): Siren state ("on", "off", or a dict with duration and volume).
"""
match state:
case "on":
Expand All @@ -73,3 +100,13 @@ def set_siren(self, state):
logging.warning("%s: Invalid siren arguments", self.name)
case _:
pass

@property
def state_event(self):
"""
Get the state event object.

Returns:
asyncio.Event: The state event object.
"""
return self._state_event
Loading
Loading