Skip to content

Commit

Permalink
Fix channels overwriting
Browse files Browse the repository at this point in the history
  • Loading branch information
akadlec committed Mar 27, 2022
1 parent 4704fb1 commit 93b122c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion fastybird_fb_bus_connector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from .bootstrap import create_connector

__version__ = "0.24.1"
__version__ = "0.25.0"

__all__ = ["connector", "bootstrap"]

Expand Down
21 changes: 17 additions & 4 deletions fastybird_fb_bus_connector/events/listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
RegisterActualValueEvent,
)
from fastybird_fb_bus_connector.logger import Logger
from fastybird_fb_bus_connector.registry.model import RegistersRegistry
from fastybird_fb_bus_connector.registry.records import (
AttributeRegisterRecord,
InputRegisterRecord,
Expand All @@ -89,6 +90,8 @@ class EventsListener: # pylint: disable=too-many-instance-attributes

__connector_id: uuid.UUID

__registers_registry: RegistersRegistry

__devices_repository: DevicesRepository
__devices_manager: DevicesManager

Expand All @@ -114,6 +117,7 @@ class EventsListener: # pylint: disable=too-many-instance-attributes
def __init__( # pylint: disable=too-many-arguments,too-many-locals
self,
connector_id: uuid.UUID,
registers_registry: RegistersRegistry,
devices_repository: DevicesRepository,
devices_manager: DevicesManager,
devices_properties_repository: DevicePropertiesRepository,
Expand All @@ -131,6 +135,8 @@ def __init__( # pylint: disable=too-many-arguments,too-many-locals
) -> None:
self.__connector_id = connector_id

self.__registers_registry = registers_registry

self.__devices_repository = devices_repository
self.__devices_manager = devices_manager

Expand Down Expand Up @@ -271,10 +277,7 @@ def __handle_create_or_update_io_register(self, event: Event) -> None:
channel_identifier=channel_identifier,
)

if channel is None or not channel.id.__eq__(event.record.id):
if channel is not None:
self.__channels_manager.delete(channel=channel)

if channel is None:
channel_data = {
"device_id": event.record.device_id,
"identifier": channel_identifier,
Expand Down Expand Up @@ -355,6 +358,16 @@ def __handle_create_or_update_io_register(self, event: Event) -> None:
},
)

# Add newly created channel identifier to register
self.__registers_registry.create_or_update(
device_id=event.record.device_id,
register_id=event.record.id,
register_type=event.record.type,
register_address=event.record.address,
register_data_type=event.record.data_type,
channel_id=channel.id,
)

# Store value for dynamic registers
self.__write_channel_property_actual_value(register=event.record)

Expand Down

0 comments on commit 93b122c

Please sign in to comment.