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

VEML7700 and VEML6030 light sensors #6067

Merged
merged 33 commits into from Mar 12, 2024
Merged

VEML7700 and VEML6030 light sensors #6067

merged 33 commits into from Mar 12, 2024

Conversation

latonita
Copy link
Contributor

@latonita latonita commented Jan 9, 2024

What does this implement/fix?

Implements component for ambient light sensors from Vishay - VEML7700 and VEML6030

Types of changes

  • Bugfix (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 not work as expected)
  • Other

Related issue or feature (if applicable): fixes
esphome/feature-requests#2493
esphome/feature-requests#218
esphome/feature-requests#1915

Pull request in esphome-docs with documentation (if applicable): esphome/esphome-docs#3525

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040
  • BK72xx
  • RTL87xx

Example entry for config.yaml:

# Example config.yaml
esphome:
  name: veml7700-test

esp32:
  board: esp32dev
  framework:
    type: arduino

# esp8266:
#   board: nodemcuv2

logger:
  level: DEBUG

i2c:

sensor:
  - platform: veml7700
    address: 0x10
    update_interval: 30s
    # lux_compensation: false
    # glass_attenuation_factor: 1.10
    # auto_mode: false
    # gain: 1x
    # integration_time: 100ms
    ambient_light:
      name: "Ambient light"
    full_spectrum:
      name: "Full spectrum"
    infrared:
      name: "Calculated Near-IR"
    actual_integration_time:
      name: "Actual integration time"
    actual_gain:
      name: "Actual gain"
    # ambient_light_counts:
    #   name: "Ambient light counts"
    # full_spectrum_counts:
    #   name: "Full spectrum counts"

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

@probot-esphome
Copy link

probot-esphome bot commented Jan 9, 2024

Hey there @latonita,
Thanks for submitting this pull request! Can you add yourself as a codeowner for this integration? This way we can notify you if a bug report for this integration is reported.
In __init__.py of the integration, please add:

CODEOWNERS = ["@latonita"]

And run script/build_codeowners.py

(message by NeedsCodeownersLabel)

@codecov-commenter
Copy link

codecov-commenter commented Jan 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 53.50%. Comparing base (4d8b5ed) to head (0dbda99).
Report is 89 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #6067      +/-   ##
==========================================
- Coverage   53.70%   53.50%   -0.21%     
==========================================
  Files          50       50              
  Lines        9408     9515     +107     
  Branches     1654     1683      +29     
==========================================
+ Hits         5053     5091      +38     
- Misses       4056     4117      +61     
- Partials      299      307       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@latonita latonita marked this pull request as draft January 10, 2024 07:56
@latonita latonita marked this pull request as ready for review January 11, 2024 00:58
Copy link
Member

@jesserockz jesserockz left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution.

I got as far as wait_for_device and decided to stop reviewing there as it will need quite a bit of reworking to be accepted in.

Please take a look at my comments below.

esphome/components/veml7700/sensor.py Outdated Show resolved Hide resolved
esphome/components/veml7700/sensor.py Outdated Show resolved Hide resolved
esphome/components/veml7700/veml7700.cpp Outdated Show resolved Hide resolved
@esphome esphome bot marked this pull request as draft January 18, 2024 07:22
@esphome
Copy link

esphome bot commented Jan 18, 2024

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@latonita latonita marked this pull request as ready for review January 19, 2024 18:07
@esphome esphome bot requested a review from jesserockz January 19, 2024 18:07
@mrtoy-me
Copy link
Contributor

Hi @latonita
I have tested the component on veml6030 seems to work fine ... but I will do some more testing overnight and let you know if I pick up anything.

Two suggestions I have
1.
I was getting some compile warnings around the packed ConfigurationRegister for IntegrationTime ALS_IT relating to gcc4.4
From what I have read, it related to the compiler complaining about the packed structure crossing a type boundary with uint8_t.
In the .h file, I changed enum IntegrationTime : uint16_t rather than uint8_t and no more warnings :) - makes no difference to packed structure anyway.
2.
There are plenty of ESP_LOGD messages in the component and I can understand why they are there when you were debugging but now it is working it makes the logs pretty noisy - I changed all the ESP_LOGD to ESP_LOGV so you can get the messages as verbose if you want and in debug there are enough messages on what values are being sent.

They are minor changes so I didn't do a PR to you, but I think they are worth you considering.

Anyway thanks a lot for developing the component - great work.

@latonita
Copy link
Contributor Author

latonita commented Jan 26, 2024

@mrtoy-me thanks for taking a look and testing

  1. I don't believe its a good thing, it just a hack which works due to specific bit positions in the struct. Stupid compilation note from the GCC drives people craze since 2010... Moreover another GCC bug doesn't let to suppress this with #pragma GCC diagnostic ignored "-Wxxxxx" :) It was fixed in 2022 in GCC 13, but extensa-gcc is based on gcc8 i believe.
    What works properly is #pragma pack(push), #pragma pack(1) ..... #pragma pack(pop) but this was removed by request from @jesserockz .
  2. Good catch, thanks! I actually forgot to change them to LOGV. Fixed.

Copy link
Member

@kbx81 kbx81 left a comment

Choose a reason for hiding this comment

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

LGTM -- thanks for working on this!

@kbx81 kbx81 dismissed jesserockz’s stale review March 12, 2024 00:41

Changes applies

@kbx81 kbx81 merged commit 5b28bd3 into esphome:dev Mar 12, 2024
56 checks passed
@latonita latonita deleted the veml7700 branch March 12, 2024 14:14
@latonita
Copy link
Contributor Author

LGTM -- thanks for working on this!

Thanks. There are several more PRs to review! :)

@jesserockz jesserockz mentioned this pull request Mar 13, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants