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

Fix breakage caused by ABCCachedProperties metaclass on Entity #487

Merged
merged 2 commits into from
Jan 6, 2024
Merged
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
17 changes: 16 additions & 1 deletion custom_components/foxess_modbus/entities/modbus_entity_mixin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Mixin providing common functionality for all entity classes"""
import logging
from abc import ABC
from typing import TYPE_CHECKING
from typing import Any
from typing import Protocol
Expand Down Expand Up @@ -73,8 +74,22 @@ class ModbusEntityProtocol(Protocol):
else:
_ModbusEntityMixinBase = object

# HA introduced a ABCCachedProperties metaclass which is used by Entity, and which derives from ABCMeta.
# This conflicts with Protocol's metaclass (from ModbusEntityProtocol).
if type(Entity) == type(ABC):
_METACLASS = type(Entity)

class ModbusEntityMixin(ModbusControllerEntity, ModbusEntityProtocol, _ModbusEntityMixinBase):
else:

class ModbusEntityMixinMetaclass(type(Entity), type(Protocol)): # type: ignore
pass

_METACLASS = ModbusEntityMixinMetaclass


class ModbusEntityMixin(
ModbusControllerEntity, ModbusEntityProtocol, _ModbusEntityMixinBase, metaclass=_METACLASS # type: ignore
):
"""
Mixin for subclasses of Entity

Expand Down
Loading