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

Xml mdib #401

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open

Conversation

deichmab-draeger
Copy link
Member

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have updated the changelog accordingly.
  • I have added tests to cover my changes.

Copy link

codecov bot commented Nov 21, 2024

Codecov Report

Attention: Patch coverage is 91.12534% with 194 lines in your changes missing coverage. Please review.

Project coverage is 90.83%. Comparing base (463564c) to head (cdf5002).

Files with missing lines Patch % Lines
src/sdc11073/entity_mdib/entity_consumermdib.py 89.05% 44 Missing ⚠️
src/sdc11073/entity_mdib/entity_transactions.py 91.45% 34 Missing ⚠️
src/sdc11073/mdib/mdibbase.py 69.23% 28 Missing ⚠️
src/sdc11073/entity_mdib/entity_providermdib.py 92.36% 21 Missing ⚠️
src/sdc11073/roles/clockprovider.py 56.25% 14 Missing ⚠️
src/sdc11073/mdib/transactions.py 87.36% 12 Missing ⚠️
...rc/sdc11073/entity_mdib/entity_providermdibxtra.py 94.69% 7 Missing ⚠️
src/sdc11073/entity_mdib/entities.py 97.40% 6 Missing ⚠️
src/sdc11073/roles/alarmprovider.py 96.47% 6 Missing ⚠️
src/sdc11073/roles/audiopauseprovider.py 90.56% 5 Missing ⚠️
... and 9 more
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.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

src/sdc11073/entity_mdib/entities.py Show resolved Hide resolved
src/sdc11073/entity_mdib/entities.py Show resolved Hide resolved
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
Copy link
Member

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

Copy link
Member Author

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.

source: ProviderInternalEntity | ProviderInternalMultiStateEntity,
mdib: EntityProviderMdib):
self._mdib = mdib
self.descriptor = copy.deepcopy(source.descriptor)
Copy link
Member

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

Copy link
Member Author

@deichmab-draeger deichmab-draeger Nov 22, 2024

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
Copy link
Member

Choose a reason for hiding this comment

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

typing should be Callable

Copy link
Member Author

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:
Copy link
Member

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?

Copy link
Member Author

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))
Copy link
Member

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

Copy link
Member Author

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,
Copy link
Member

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

Copy link
Member Author

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,
Copy link
Member

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]

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