Skip to content

Commit

Permalink
chore: add poetry scripts (#772)
Browse files Browse the repository at this point in the history
* chore: Wrap main functionality in functions

* feature: Add peotry scripts

* chore: Add description to main functions

* chore: update main readme with running scripts via poetry
  • Loading branch information
5c077m4n authored May 31, 2024
1 parent 73a752b commit 32e8073
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ asyncio.run(print_devices(60))
## Command Line Helper Scripts

- [discover_devices.py](https://github.com/TomerFi/aioswitcher/blob/dev/scripts/discover_devices.py) can discover devices and their
states.
- [control_device.py](https://github.com/TomerFi/aioswitcher/blob/dev/scripts/control_device.py) can control a device.
states (can be run by `poetry run discover_devices`).
- [control_device.py](https://github.com/TomerFi/aioswitcher/blob/dev/scripts/control_device.py) can control a device (can be run by `poetry run control_device`).

## Disclaimer

Expand Down
9 changes: 7 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ classifiers = [
include = [ ]
exclude = [ ]

[tool.poetry.dependencies]
python = "^3.9.0"
[tool.poetry.dependencies]
python = "^3.9.0"

[tool.poetry.group.dev.dependencies]
assertpy = "^1.1"
Expand Down Expand Up @@ -108,3 +108,8 @@ skip_covered = true
[build-system]
requires = [ "poetry-core>=1.2.0" ]
build-backend = "poetry.core.masonry.api"

[tool.poetry.scripts]
control_device = "scripts.control_device:main"
discover_devices = "scripts.discover_devices:main"
get_device_login_key = "scripts.get_device_login_key:main"
7 changes: 6 additions & 1 deletion scripts/control_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,8 @@ async def set_shutter_position(
)


if __name__ == "__main__":
def main() -> None:
"""Run the device controller script."""
try:
args = main_parser.parse_args()

Expand Down Expand Up @@ -572,3 +573,7 @@ async def set_shutter_position(

except KeyboardInterrupt:
exit()


if __name__ == "__main__":
main()
7 changes: 6 additions & 1 deletion scripts/discover_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ def on_device_found_callback(device: SwitcherBase) -> None:
await asyncio.sleep(delay)


if __name__ == "__main__":
def main() -> None:
"""Run the device discovery script."""
args = parser.parse_args()

if args.type == "1":
Expand All @@ -132,3 +133,7 @@ def on_device_found_callback(device: SwitcherBase) -> None:
asyncio.run(print_devices(args.delay, ports))
except KeyboardInterrupt:
exit()


if __name__ == "__main__":
main()
7 changes: 6 additions & 1 deletion scripts/get_device_login_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,13 @@ def listen_udp(specific_ip: str, port: int) -> None:
sock.close()


if __name__ == "__main__":
def main() -> None:
"""Fetch the devices's login key."""
args = parser.parse_args()
print("ip address: " + args.ip_address)
print("port: " + str(args.port))
listen_udp(args.ip_address, args.port)


if __name__ == "__main__":
main()

0 comments on commit 32e8073

Please sign in to comment.