v0.1.43 - Add device() factory function (2025-12-14)¶
What Changed?¶
This release introduces a new device() factory function that provides a unified interface for creating both real hardware devices (PortDevice) and mock devices (MockDevice) for testing. It simplifies the API for library users and improves code maintainability by eliminating internal duplication in the CLI.
What's New¶
Main Feature: Unified Device Factory Function¶
What it does:
The new device() function is a flexible factory that returns either a PortDevice (for real hardware) or MockDevice (for testing) based on the mock parameter. This provides a single, consistent interface for device creation while maintaining backward compatibility with the existing connect() function.
How to use it:
from kazunoko import device, Command
# Real hardware (auto-detect port)
with device() as dev:
cmd = Command(dev)
status = cmd.status()
# Mock device for testing
with device(mock=True) as dev:
cmd = Command(dev)
status = cmd.status()
# Specific port
with device(port="/dev/ttyUSB0") as dev:
cmd = Command(dev)
status = cmd.status()
Code example:
# Easy to switch between real and mock for testing
def run_command(use_mock=False):
with device(mock=use_mock) as dev:
cmd = Command(dev)
return cmd.status()
# Production: use real hardware
production_status = run_command(use_mock=False)
# Testing: use mock device
test_status = run_command(use_mock=True)
Installation¶
Quick Start¶
# Get the release
git checkout v0.1.43
# Setup
uv sync
# Run CLI
uv run kazunoko --help
What's Different from the Last Version?¶
✅ Added¶
- New
device()factory function indevice.pyfor flexible device selection - Public API export of
device()in__init__.py - Public API export of
MockGeneratorin__init__.py
🔧 Changed¶
- Refactored CLI commands to use new
device()function instead of internal_get_device() - All CLI commands (query, status, usage, threshold, reset) now use unified device factory
- Improved code consistency across CLI layer
🐛 Fixed¶
- Eliminated internal code duplication in
cli.pyby removing_get_device()
Is It Safe to Upgrade?¶
Backward Compatible: Yes
- No breaking changes to existing APIs
connect()function remains unchanged and continues to work as before- Existing code using
PortDevicedirectly unaffected MockDevicewas already available, now also exported in public API for convenience- All CLI commands work identically to previous version
Tests Passed¶
- ✅ Builds without errors
- ✅ Mock device functionality verified
- ✅ All Command methods work with device() function
- ✅ CLI commands successfully use device() factory
- ✅ Linting (ruff) passed
Release Details¶
- Date: 2025-12-14
- Version: v0.1.43
- Files Changed: 3
src/kazunoko/device.py- Addeddevice()functionsrc/kazunoko/cli.py- Refactored to usedevice()src/kazunoko/__init__.py- Exporteddevice()andMockGenerator- Commits:
ce7cdb3(feat: add device() factory function for flexible device selection)
Next Steps¶
- Consider adding type stubs for better IDE integration with
device()function - Explore async device support in future versions
- Add more comprehensive examples in documentation