Skip to content

v0.1.44 - MockDevice Port Attribute (2025-12-14)

What Changed?

This release adds a port attribute to the MockDevice class to unify the interface with PortDevice. The port attribute is set to "mock" for mock devices, enabling consistent port display in CLI output and improving type safety. CLI code is simplified by removing conditional logic for device type detection.


What's New

MockDevice Port Attribute

What it does: The MockDevice class now has a port attribute set to "mock", matching the interface of PortDevice. This allows unified port access across both device types without conditional logic.

How to use it: The port attribute is automatically set when creating a MockDevice. In CLI commands, you can now access dev.port directly for both real and mock devices.

Code example:

from kazunoko import MockDevice

device = MockDevice()
print(device.port)  # Output: "mock"

# Works the same as PortDevice
with device:
    response = device.query("STATUS")

Installation

Quick Start

# Get the release
git checkout vX.Y.Z

# Setup
task env:setup

# Run CLI
uv run kazunoko --help

What's Different from the Last Version?

✅ Added

  • port attribute to MockDevice class (set to "mock")

🔧 Changed

  • CLI commands now use dev.port directly instead of conditional logic
  • Simplified port display in verbose output for all commands (query, status, usage, threshold, reset, measure)

🐛 Fixed

  • Type checker warnings when accessing port on device with type DeviceProtocol

Is It Safe to Upgrade?

Backward Compatible: Yes

  • No breaking changes. The port attribute is a new addition and does not affect existing functionality.
  • Existing code using MockDevice continues to work as before.
  • CLI output format remains unchanged.

Tests Passed

  • ✅ Builds without errors
  • ✅ MockDevice instantiation and port attribute access
  • ✅ CLI commands work with both PortDevice and MockDevice
  • ✅ Type checker validation (mypy)

Release Details

  • Date: 2025-12-14
  • Version: v0.1.44
  • Files Changed: 2
  • src/kazunoko/mock.py: Added port attribute to MockDevice.__init__
  • src/kazunoko/cli.py: Simplified port display logic in 6 CLI commands
  • Breaking Changes: None

Next Steps

  • Consider adding timeout and baudrate attributes to MockDevice for further interface unification
  • Potential enhancement of DeviceProtocol to formally include port attribute for better type safety