Skip to content

Commit

Permalink
Added repository event
Browse files Browse the repository at this point in the history
  • Loading branch information
akadlec committed Nov 27, 2021
1 parent e3a5d67 commit d6739d0
Show file tree
Hide file tree
Showing 5 changed files with 275 additions and 9 deletions.
2 changes: 1 addition & 1 deletion devices_module/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Devices module
"""

__version__ = "0.5.12"
__version__ = "0.5.13"
93 changes: 93 additions & 0 deletions devices_module/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
from pony.orm import core as orm
from whistle import Event

# Library libs
from devices_module.items import RepositoryItem


class ModelEntityCreatedEvent(Event):
"""
Expand Down Expand Up @@ -111,3 +114,93 @@ def __init__(
def entity(self) -> orm.Entity:
"""Deleted entity instance"""
return self.__entity


class ModelItemCreatedEvent(Event):
"""
Event fired by model when new item is created
@package FastyBird:DevicesModule!
@module events
@author Adam Kadlec <adam.kadlec@fastybird.com>
"""

__item: RepositoryItem

EVENT_NAME: str = "devices-module.itemCreated"

# -----------------------------------------------------------------------------

def __init__(
self,
item: RepositoryItem,
) -> None:
self.__item = item

# -----------------------------------------------------------------------------

@property
def item(self) -> RepositoryItem:
"""Created item instance"""
return self.__item


class ModelItemUpdatedEvent(Event):
"""
Event fired by model when existing item is update
@package FastyBird:DevicesModule!
@module events
@author Adam Kadlec <adam.kadlec@fastybird.com>
"""

__item: RepositoryItem

EVENT_NAME: str = "devices-module.itemUpdated"

# -----------------------------------------------------------------------------

def __init__(
self,
item: RepositoryItem,
) -> None:
self.__item = item

# -----------------------------------------------------------------------------

@property
def item(self) -> RepositoryItem:
"""Updated item instance"""
return self.__item


class ModelItemDeletedEvent(Event):
"""
Event fired by model when existing item is deleted
@package FastyBird:DevicesModule!
@module events
@author Adam Kadlec <adam.kadlec@fastybird.com>
"""

__item: RepositoryItem

EVENT_NAME: str = "devices-module.itemDeleted"

# -----------------------------------------------------------------------------

def __init__(
self,
item: RepositoryItem,
) -> None:
self.__item = item

# -----------------------------------------------------------------------------

@property
def item(self) -> RepositoryItem:
"""Deleted item instance"""
return self.__item
23 changes: 17 additions & 6 deletions devices_module/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,18 @@
from modules_metadata.types import DataType


class DeviceItem:
class RepositoryItem(ABC):
"""
Repository base item
@package FastyBird:DevicesModule!
@module items
@author Adam Kadlec <adam.kadlec@fastybird.com>
"""


class DeviceItem(RepositoryItem):
"""
Device entity base item
Expand Down Expand Up @@ -224,7 +235,7 @@ def to_dict(self) -> Dict[str, Union[str, int, bool, None]]:
}


class ChannelItem:
class ChannelItem(RepositoryItem):
"""
Channel entity base item
Expand Down Expand Up @@ -318,7 +329,7 @@ def to_dict(self) -> Dict[str, Union[str, int, bool, None]]:
}


class PropertyItem(ABC):
class PropertyItem(RepositoryItem):
"""
Property entity base item
Expand Down Expand Up @@ -596,7 +607,7 @@ def to_dict(self) -> Dict[str, Union[str, int, bool, None]]:
}


class ConnectorItem(ABC):
class ConnectorItem(RepositoryItem):
"""
Connector entity item
Expand Down Expand Up @@ -817,7 +828,7 @@ def to_dict(self) -> Dict[str, Union[str, int, bool, None]]:
}


class ControlItem(ABC):
class ControlItem(RepositoryItem):
"""
Control entity base item
Expand Down Expand Up @@ -1012,7 +1023,7 @@ def to_dict(self) -> Dict[str, str]:
}


class ConfigurationItem(ABC):
class ConfigurationItem(RepositoryItem):
"""
Configuration entity base item
Expand Down
Loading

0 comments on commit d6739d0

Please sign in to comment.