-
Notifications
You must be signed in to change notification settings - Fork 27
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
Xml mdib #401
base: master
Are you sure you want to change the base?
Xml mdib #401
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #401 +/- ##
==========================================
- Coverage 90.84% 90.83% -0.01%
==========================================
Files 116 125 +9
Lines 12963 14660 +1697
==========================================
+ Hits 11776 13317 +1541
- Misses 1187 1343 +156 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
f'State handle {state_handle} already exists in {self.__class__.__name__}, handle = {self.handle}') | ||
cls = self._mdib.data_model.get_state_container_class(self.descriptor.STATE_QNAME) | ||
state = cls(descriptor_container=self.descriptor) | ||
state.Handle = state_handle or self.handle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handles should be unique. dont take the descriptor handle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a context state in a SetContextState operation has Handle == DescriptorHandle, this tells the provider that it shall insert a new context state. The provider changes the Handle to something unique.
This code creates a context state that can directly be used as a new state for SetContextState.
Therefore I think the provided code is correct as it is.
src/sdc11073/entity_mdib/entities.py
Outdated
source: ProviderInternalEntity | ProviderInternalMultiStateEntity, | ||
mdib: EntityProviderMdib): | ||
self._mdib = mdib | ||
self.descriptor = copy.deepcopy(source.descriptor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of copy use xml_utils.copy...
methods. check other occurences
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
those copy methods only copy lxml nodes, not state/descriptor containers. I implemented a local copy method that creates a deep copy of the container, but without the node element.
@dataclass | ||
class _BufferedData: | ||
received_message_data: ReceivedMessage | ||
handler: callable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typing should be Callable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
self._entities = entities | ||
self._mdib = mdib | ||
|
||
def handle(self, handle: str) -> ConsumerEntityType | None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the method name itself is kinda confusing. maybe change to by_handle
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed. Changed all getter to by_xxx
ret = [] | ||
for handle, entity in self._entities.items(): | ||
if entity.node_type == node_type: | ||
ret.append(self._mk_entity(handle)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of collecting all entities and returning a list, you could also just use yield
. Check other methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It turned out that this and the following getter methods need to use mdib_lock, because the iterable could change during iteration. Using yield would allow the user to block the lock for a long time, while returning a list would only hold the lock as short has possible.
# for testing purpose you can disable checking of mdib version, so that every notification is accepted. | ||
|
||
def __init__(self, | ||
sdc_client: SdcConsumer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sdc_client
-> sdc_consumer
or just consumer
.
You could also instead just get the GetService
as the variable is just used for that. also init_mdib
can then be called from the consumer which reduces circular dependencies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I implemented the identical interface as old mdib so that they can easily be exchanged. API change only with major version update..
|
||
def __init__(self, | ||
sdc_client: SdcConsumer, | ||
extras_cls: type | None = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be extras_cls: Callable[[EntityConsumerMdib, LoggerAdapter], Any] = EntityConsumerMdibMethods
or create a protocol type for this, as further down below self._xtra.bind_to_client_observables() is called. so type should be Callable[[EntityConsumerMdib, LoggerAdapter], EntityConsumerMdibMethodsProtocols]
Types of changes
Checklist: