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

Add support for additional sensors from BME680 #288

Conversation

BenBergman
Copy link
Contributor

This PR addresses issue #277. I also fixed a typo for Print Projected Total Duration. With all the additional sensors added, I opted to append the sensor type to the name of the sensor from Moonraker, including the temperature. While that works better for my BME680 multisensor, I could see why it might be undesirable for other temperature sensors.

Something I've left unaddressed is the precision of the new sensors. I'm new to Home Assistant integrations and I don't do much Python. I'm seeing way too many digits right now. I can manually set it in Home Assistant, but it would be better to set it in the integration.

image

@BenBergman
Copy link
Contributor Author

I think the failed tests are a result of the " Temperature" string added to the names, but I'm not 100% sure.

Copy link
Owner

@marcolivierarsenault marcolivierarsenault left a comment

Choose a reason for hiding this comment

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

I am not sure what you are trying to do exactly tbh,

But this _temperature does not work for other elements

This is also why unit tests are failing

@@ -370,7 +370,7 @@ async def async_setup_optional_sensors(coordinator, entry, async_add_entities):
desc = MoonrakerSensorDescription(
key=f"{split_obj[0]}_{split_obj[1]}",
status_key=obj,
name=split_obj[1].replace("_", " ").title(),
name=split_obj[1].replace("_", " ").title() + " Temperature",

Choose a reason for hiding this comment

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

This creates not ideal naming, also the reason why test are failing
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm adding the " Temperature" since the sensor can provide more than just temperature. For me, in Klipper I've got the sensor named "Enclosure", so the names of all the Home Assistant sensors become "Enclosure Temperature", "Enclosure Humidity", etc.

Without adding " Temperature" to the temp sensor, I either have the temperature labelled "Enclosure" and the humidity labelled "Enclosure Humidity" or with your example "MCU Temp" and "MCU Temp Humidity".

I suppose I could not add " Humidity" etc. to any of the names and just refer to the units, but that makes searching entities in HASS harder.

Choose a reason for hiding this comment

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

I think if we want to go that path, you would need to remove the _temp from all of them

so it goes, mcu_temperature, mcu_humidity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For my enclosure, there is no _temp as I did not include it in the name. My MCU doesn't report temp, but I guess _temp is automatically added by moonraker? If so, I can strip that out if present.

So basically instead of

name=split_obj[1].replace("_", " ").title() + " Temperature",

we want

name=split_obj[1].removesuffix("_temp").replace("_", " ").title() + " Temperature",

right?

Choose a reason for hiding this comment

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

actually,

do we want to keep the format, so it introduce no change for existing users.

example
name=split_obj[1].removesuffix("_temp").replace("_", " ").title() + "_temp",

and for the others

name=split_obj[1].removesuffix("_temp").replace("_", " ").title() + "_humidity",
etc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could do that. I don't love the shorted "temp" instead of "temperature", but it seems a reasonable tradeoff to get the new functionality without damaging existing installs.

That said, I think the name field is the display name (hence the replace("_", " "). I guess the sensor names are derived from that display name?

@marcolivierarsenault
Copy link
Owner

@BenBergman just need to update testing to make sure you have coverage and it should be good

@marcolivierarsenault marcolivierarsenault force-pushed the bme280_additional_sensors branch from e660274 to 5448af7 Compare March 22, 2024 11:55
@BenBergman
Copy link
Contributor Author

I was out of town for a bit, but back now. Will try to get coverage updated later this week.

@BenBergman BenBergman force-pushed the bme280_additional_sensors branch from e458eb0 to bb78e80 Compare March 31, 2024 02:55
@marcolivierarsenault marcolivierarsenault merged commit 593461d into marcolivierarsenault:main Apr 1, 2024
6 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.

2 participants