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

[2.0] Add Floors, Labels, and additional device properties #290

Merged
merged 19 commits into from
May 20, 2024

Conversation

strawgate
Copy link
Collaborator

@strawgate strawgate commented Apr 26, 2024

Add floors support for devices
Add labels support for devices and entities
Add unit_of_measure for entities
Add class for devices (device_class, ex. timestamp) and entities (state_class)

Switch dynamic mode from strict to false to ignore extra fields present in the documents instead of failing to index

Bumps Python to 3.12 and minimum HA version to 2024.4.4

Ready to go on everything except updating doc_creator and doc_publisher tests as I want to wait until #272 merges before updating those tests

Resolves #249
Resolves #299

@strawgate
Copy link
Collaborator Author

Fixes #249

@strawgate strawgate changed the title [Draft] Add Floors and Labels support Add Floors and Labels support Apr 27, 2024
@strawgate
Copy link
Collaborator Author

consider also adding state_class

@strawgate strawgate changed the title Add Floors and Labels support Add Floors, Labels, and additional device properties May 1, 2024
@strawgate
Copy link
Collaborator Author

#299

@strawgate strawgate changed the title Add Floors, Labels, and additional device properties [2.0] Add Floors, Labels, and additional device properties May 2, 2024
@legrego legrego added this to the Version 2.0 milestone May 3, 2024
@strawgate strawgate enabled auto-merge (squash) May 3, 2024 21:20
Copy link
Contributor

github-actions bot commented May 3, 2024

Coverage

Coverage Report
FileStmtsMissCoverMissing
__init__.py00100% 
elasticsearch
   __init__.py1121983%96, 99–101, 104, 110, 119, 137–138, 145–147, 153–154, 174–175, 181, 183, 269
   config_flow.py1991691%163, 196, 326, 390–391, 402–404, 418–419, 423, 501, 576, 585, 619–620
   const.py340100% 
   entity_details.py590100% 
   errors.py28389%51, 60, 67
   es_doc_creator.py194199%353
   es_doc_publisher.py2683885%142–143, 182, 185, 188, 193, 210–211, 229–232, 236, 251–252, 268–269, 273, 298, 302, 396, 416, 458, 472, 483, 486, 514–515, 517–518, 520–521, 525–527, 546, 548, 554
   es_gateway.py1442086%94–95, 114, 133–135, 137, 139–140, 142–143, 146–148, 153–154, 158–160, 253
   es_index_manager.py1491887%77, 82, 182–183, 255–256, 273–274, 279–280, 309–310, 315, 323–324, 337, 350–351
   es_integration.py35877%40, 45–46, 57–61
   es_privilege_check.py610100% 
   es_serializer.py10190%17
   es_version.py300100% 
   logger.py20100% 
   system_info.py25196%37
   utils.py40100% 
TOTAL135412590% 

Tests Skipped Failures Errors Time
223 0 💤 0 ❌ 0 🔥 14.992s ⏱️

@strawgate
Copy link
Collaborator Author

@legrego good to go!

Copy link
Owner

@legrego legrego left a comment

Choose a reason for hiding this comment

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

Thanks for your patience, I know I've been slow with reviews lately. Code-review only, will test locally for the next iteration

custom_components/elasticsearch/es_index_manager.py Outdated Show resolved Hide resolved
"unit_of_measurement": str(entity.unit_of_measurement),
"area.id": entity_area.id if entity_area else None,
"area.name": entity_area.name if entity_area else None,
"class": entity_capabilities.get("state_class"),
Copy link
Owner

Choose a reason for hiding this comment

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

question Why did you choose class over state_class for the property name?

Copy link
Collaborator Author

@strawgate strawgate May 16, 2024

Choose a reason for hiding this comment

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

value is technically state.value so I was thinking that just class might make sense here, I think in the other PR i lift device_class to be device.class. Happy to just call it state_class though.


        device_additions = {
            "class": entity.device_class or entity.original_device_class,
            "class": entity_capabilities.get("state_class"),

Copy link
Owner

Choose a reason for hiding this comment

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

I slightly prefer state_class. Leaving this as entity.class gives me the impression that this describes the class of the entity, as opposed to the entity's state.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

are you okay with me merging this PR and making new open issues for this and moving the Area and I'll incorporate those into my next PR?

Copy link
Owner

Choose a reason for hiding this comment

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

Yes that would be fine with me

custom_components/elasticsearch/es_doc_creator.py Outdated Show resolved Hide resolved
custom_components/elasticsearch/entity_details.py Outdated Show resolved Hide resolved
custom_components/elasticsearch/entity_details.py Outdated Show resolved Hide resolved
custom_components/elasticsearch/entity_details.py Outdated Show resolved Hide resolved
custom_components/elasticsearch/entity_details.py Outdated Show resolved Hide resolved
@@ -147,6 +162,17 @@
"type": "keyword"
}
}
},
"floor": {
Copy link
Owner

Choose a reason for hiding this comment

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

I'm torn about placing floor here, as it's technically an attribute of the area. I think it's easier to consume where you have it, but the pedant in me says it doesn't belong here.

Let's leave it the way you have it for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Are you sure? I'd be happy to move it under the Area

Copy link
Owner

Choose a reason for hiding this comment

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

Let's move it under area for both entity.area and device.area, if you don't mind.

@strawgate
Copy link
Collaborator Author

@legrego 3 open discussions but incorporated the rest of the feedback

Copy link
Owner

@legrego legrego left a comment

Choose a reason for hiding this comment

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

LGTM, with naming nits for follow-up

device = self._registry_device.async_get(entity.device_id)
if device.area_id:
device_area = self._registry_area.async_get_area(device.area_id)
entity_label = self.async_get_entity_labels(entity)
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
entity_label = self.async_get_entity_labels(entity)
entity_labels = self.async_get_entity_labels(entity)

if device is None:
LOGGER.debug("Device not found for entity: %s", entity_id)

device_label = self.async_get_device_labels(device)
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
device_label = self.async_get_device_labels(device)
device_labels = self.async_get_device_labels(device)

entity,
entity_area,
entity_floor,
entity_label,
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
entity_label,
entity_labels,

device,
device_area,
device_floor,
device_label,
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
device_label,
device_labels,

"unit_of_measurement": str(entity.unit_of_measurement),
"area.id": entity_area.id if entity_area else None,
"area.name": entity_area.name if entity_area else None,
"class": entity_capabilities.get("state_class"),
Copy link
Owner

Choose a reason for hiding this comment

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

Yes that would be fine with me

@strawgate strawgate merged commit da8c76a into legrego:main May 20, 2024
3 checks passed
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.

Strict dynamic mapping is going to cause issues Add support for Floors and Labels
2 participants