Skip to content

Add Category enum and mixin for NACamDoorTag#553

Open
farkasdi wants to merge 4 commits intojabesq-org:developmentfrom
farkasdi:doortag-category
Open

Add Category enum and mixin for NACamDoorTag#553
farkasdi wants to merge 4 commits intojabesq-org:developmentfrom
farkasdi:doortag-category

Conversation

@farkasdi
Copy link

@farkasdi farkasdi commented Mar 10, 2026

For NACamDoorTag there is a category that describes what type of opening the doortag is used. The change is proposing a doortag_category among the device feature-s to expose this.

Summary by Sourcery

Introduce a category concept for NACamDoorTag modules and expose it via the module feature set.

New Features:

  • Add a DoorTagCategory enum to represent NACamDoorTag opening types such as door, window, garage, and others.
  • Introduce a DoorTagCategoryMixin to surface the category field as a module feature and apply it to NACamDoorTag entities.

@farkasdi farkasdi requested review from cgtobi and jabesq as code owners March 10, 2026 14:37
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Mar 10, 2026

Reviewer's Guide

Introduce a Category enum and CategoryMixin to expose the NACamDoorTag module's category field (door, window, etc.) as a first-class feature and wire the mixin into the NACamDoorTag device type.

Class diagram for new Category enum and CategoryMixin integration into NACamDoorTag

classDiagram

class Category {
    <<enumeration>>
    door
    furniture
    garage
    gate
    other
    window
    unknown
    +_missing_(key: object) Category
}

class EntityBase {
}

class CategoryMixin {
    +category: Category | None
    +__init__(home: Home, module: ModuleT)
}

class Module {
}

class StatusMixin {
}

class FirmwareMixin {
}

class BatteryMixin {
}

class RfMixin {
}

class NACamDoorTag {
}

CategoryMixin --|> EntityBase

NACamDoorTag --|> Module
NACamDoorTag --|> StatusMixin
NACamDoorTag --|> FirmwareMixin
NACamDoorTag --|> BatteryMixin
NACamDoorTag --|> RfMixin
NACamDoorTag --|> CategoryMixin

CategoryMixin --> Category
Loading

File-Level Changes

Change Details Files
Add a Category enum type representing NACamDoorTag categories with graceful handling of unknown values.
  • Define Category as a str-backed Enum with values like door, furniture, garage, gate, other, window, and unknown.
  • Implement a missing classmethod that logs a warning and returns Category.unknown when an unknown category value is encountered.
src/pyatmo/modules/device_types.py
Introduce a CategoryMixin to expose the category attribute from module data and treat it as a common feature on modules that support it.
  • Add category to the MODULE_FEATURES-style list so it is treated as an exposed feature.
  • Implement CategoryMixin inheriting from EntityBase, with a category-typed attribute and init that reads the category field from the module dict with a default of Category.unknown (note: currently stored on self.appliance_type rather than self.category, which may merit review).
src/pyatmo/modules/module.py
Wire CategoryMixin into NACamDoorTag so door tags expose category information.
  • Import CategoryMixin into the netatmo module.
  • Extend NACamDoorTag's base classes to include CategoryMixin so the device exposes its category feature.
src/pyatmo/modules/netatmo.py

Possibly linked issues

  • #Add missing device category field: PR implements a Category enum/mixin on NACamDoorTag to expose the requested category field from data.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues, and left some high level feedback:

  • In CategoryMixin.__init__ you assign to self.appliance_type instead of self.category, which makes the mixin inconsistent with its own type annotation and the new category feature; this likely should be self.category = module.get("category", Category.unknown).
  • Consider aligning naming between CategoryMixin and the Category enum docstring: the mixin is generic but the enum is documented as specific to NACamDoorTag/Home+Security, so either narrow the mixin’s scope or generalize the docstring to avoid confusion about intended usage.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `CategoryMixin.__init__` you assign to `self.appliance_type` instead of `self.category`, which makes the mixin inconsistent with its own type annotation and the new `category` feature; this likely should be `self.category = module.get("category", Category.unknown)`.
- Consider aligning naming between `CategoryMixin` and the `Category` enum docstring: the mixin is generic but the enum is documented as specific to NACamDoorTag/Home+Security, so either narrow the mixin’s scope or generalize the docstring to avoid confusion about intended usage.

## Individual Comments

### Comment 1
<location path="src/pyatmo/modules/module.py" line_range="324-330" />
<code_context>
+class CategoryMixin(EntityBase):
+    """Mixin for category data."""
+
+    category: Category | None
+
+    def __init__(self, home: Home, module: ModuleT) -> None:
+        """Initialize category mixin."""
+
+        super().__init__(home, module)
+        self.appliance_type: Category | None = module.get(
+            "category",
+            Category.unknown,
</code_context>
<issue_to_address>
**issue (bug_risk):** Mismatch between declared `category` attribute and assigned `appliance_type` plus inconsistent optional typing.

`CategoryMixin` defines `category: Category | None`, but `__init__` sets `self.appliance_type: Category | None = module.get("category", Category.unknown)`. This likely leaves `self.category` unset and introduces an unintended `appliance_type` attribute. Also, the type allows `None` but the default is `Category.unknown`, so `None` is never stored. Please align the attribute name and type, e.g.:

```python
self.category: Category = Category(module.get("category", Category.unknown))
```

(or make the annotation non-optional) so naming, typing, and the stored value are consistent.
</issue_to_address>

### Comment 2
<location path="src/pyatmo/modules/module.py" line_range="330-332" />
<code_context>
+        """Initialize category mixin."""
+
+        super().__init__(home, module)
+        self.appliance_type: Category | None = module.get(
+            "category",
+            Category.unknown,
+        )
+
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Raw category value is stored without validating or converting it to the `Category` enum.

`module.get("category", Category.unknown)` is assigned directly to a `Category | None`, but `module` likely stores raw strings. This can leave `appliance_type` as a plain string instead of a `Category` member, breaking enum comparisons later. Convert the value via `Category(...)` (handling `ValueError` as needed) so the mixin always exposes a valid enum instance.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@farkasdi
Copy link
Author

2026-03-11 10:31:33.688 DEBUG (MainThread) [homeassistant.components.netatmo.binary_sensor] Netatmo device: {'entity_id': 'XX:XX:XX:XX:XX:XX', 'name': 'Minibar', 'history_features_values': {}, 'history_features': set(), 'device_type': <DeviceType.NACamDoorTag: 'NACamDoorTag'>, 'home': <pyatmo.home.Home object at 0xXXXXXXXXXX>, 'room_id': 'XXXXXXXXX', 'reachable': True, 'bridge': 'XX:XX:XX:XX:XX:XX', 'modules': None, 'device_category': <DeviceCategory.opening: 'opening'>, 'features': {'status', 'rf_strength', 'battery', 'reachable', 'doortag_category'}, 'doortag_category': <DoorTagCategory.furniture: 'furniture'>, 'rf_strength': 55, 'battery_state': 'high', 'battery_level': 5420, 'battery_percent': None, 'firmware_revision': 58, 'firmware_name': None, 'status': 'closed'}

@farkasdi farkasdi requested a review from cgtobi March 11, 2026 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants