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

chore: include context conversion methods and test #393

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

Conversation

sbanoeon
Copy link
Contributor

No description provided.

@sbanoeon sbanoeon requested a review from djs0109 February 17, 2025 10:01
@@ -623,6 +623,12 @@ def test_get_attributes(self):
self.assertNotEqual(entity.get_attributes(strict_data_type=True), attributes)
self.assertNotEqual(entity.get_attributes(), attributes)

def test_context_conversion(self):
entity_normalized = ContextEntity(**self.entity_data)
entity_key_values = ContextEntityKeyValues(**self.entity_data)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this way the created entity_key_values is not really in keyvalue format.
Expected entity_key_values.model_dump_json()

{"id": "MyId", "type": "MyType", "temperature": 20, "relation": "OtherEntity"}

Right now

{"id": "MyId", "type": "MyType", "temperature": {"value": 20, "type": "Number"}, "relation": {"value": "OtherEntity", "type": "Relationship"}}

Copy link
Contributor

Choose a reason for hiding this comment

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

I made adjustments accordingly. However, the test is failing, so the conversion functionality needs to be checked again.

Copy link
Contributor Author

@sbanoeon sbanoeon Feb 18, 2025

Choose a reason for hiding this comment

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

Hmm, now I am thinking, shouldn't the constructor of ContextEntityKeyValues class take care of the right format?

Copy link
Contributor

@djs0109 djs0109 Feb 18, 2025

Choose a reason for hiding this comment

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

Not really, I think the implementation was quite simple. There is no need to create model for AttributeKeyvalue. Because the entity can simply takes whatever it gets, as long as it is JSON serializable. It would be nice to have a simple validation mechanism for the AttributeKeyvalue, but not necessarily
For example, if we create an entity with keyvalue like that

{"id": "MyId", "type": "MyType", "temperature": {"value": 20, "type": "Number"}

Orion will understand it as

{"id": "MyId", "type": "MyType",
 "temperature": {
   "type": "StructuredValue",
   "value": {"value": 20, "type": "Number"}
}

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