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

New sensor component : ds248x #6616

Draft
wants to merge 46 commits into
base: dev
Choose a base branch
from
Draft

New sensor component : ds248x #6616

wants to merge 46 commits into from

Conversation

alainstark
Copy link

@alainstark alainstark commented Apr 23, 2024

What does this implement?

This new component help to build wide and reliable 1-wire network. It support for now only temperature sensors of type ds18b20.

This component is writen to drive ds248x family of I²C to 1-wire bus.

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

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

Test Environment

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

Example entry for config.yaml:

# Example config.yaml
esphome:
  name: "olimex-01"
  friendly_name: "olimex-01"

esp32:
  board: esp32-poe-iso

# Enable logging
logger:
  # level: INFO
  level: DEBUG
  # level: VERBOSE
  # level: VERY_VERBOSE

<<: !include inc/olimex_network.yaml
<<: !include inc/auth.yaml

external_components:
  # source: github://mknjc/esphome@ds248x
  source:
    type: local
    path: local_components
  components: [ ds248x ]

i2c:
  sda: GPIO13 # set your i2c pins
  scl: GPIO16 # set your i2c pins
  id: bus_a
  frequency: 400kHz # 400 is the maximum the ds2484 supports

ds248x:
  i2c_id: bus_a
  type: ds2482-800
  address: 0x1f # should be the default
#  sleep_pin: 32 # remove if not needed, if set the ds248x sleeps when no transaction is in progress
  active_pullup: true # adds a active pullup which should improve signal integrity
  strong_pullup: false
  bus_sleep: false
#  strong_pullup: true # enables a strong pullup used to provide the needed current for temperature reading without vcc connected
#  bus_sleep: true # power down the bus when no transaction is in progres
  update_interval: 10s

sensor:

# Channel 0

  - platform: ds248x
    address: 0x80000002a5fea828
    channel: 0
    name: "Temp-01"
    resolution: 12

  - platform: ds248x
    address: 0x3a000002ceac6928
    channel: 0
    name: "Temp-02"
    resolution: 12

  - platform: ds248x
    address: 0x3a000002ceac6928
    channel: 0
    name: "Temp-03"
    resolution: 12

# Channel 1

  - platform: ds248x
    address: 0xf10000051c169828
    channel: 1
    name: "Temp-04"
    resolution: 12

  - platform: ds248x
    address: 0xda000002cea33128
    channel: 1
    name: "Temp-05"
    resolution: 12

  - platform: ds248x
    address: 0xe9000002ce987728
    channel: 1
    name: "Temp-06"
    resolution: 12

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

Hey there @alainstark,
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 = ["@alainstark"]

And run script/build_codeowners.py

(message by NeedsCodeownersLabel)

@codecov-commenter
Copy link

codecov-commenter commented Apr 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 54.24%. Comparing base (4d8b5ed) to head (0a6698d).
Report is 561 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #6616      +/-   ##
==========================================
+ Coverage   53.70%   54.24%   +0.53%     
==========================================
  Files          50       50              
  Lines        9408     9581     +173     
  Branches     1654     1688      +34     
==========================================
+ Hits         5053     5197     +144     
- Misses       4056     4060       +4     
- Partials      299      324      +25     

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

@nagyrobi
Copy link
Member

Please edit the top message by specifying the PR number for the docs.
Add your codeowners as suggested by the bot.
Please add some tests to the esphome\tests directory. It needs a basic config-like yaml just with the dependency components you need this component to run, with some dummy config.

@nagyrobi
Copy link
Member

You can also link the feature request to the "Related issue or feature (if applicable): fixes" sentece in the opening message.

import CONF_CHANNEL from const.py
CONF_DS248X_TYPE not match value
Import CONF_TYPE from const.py
Suppress local CONF_TYPE const
Macros not allowed
@alainstark
Copy link
Author

Hello,
I have a problem with CODEOWNERS
I am not the principal writer of this component. I have only adapt this to support ds2482-800 the principal writer is mkncj.
mkncj/esphome

add CODEOWNERS
remove CODEOWNERS
Add CODEOWNERS
@martijnbuts
Copy link

What board did you use for testing?

@alainstark
Copy link
Author

I use an Olimex esp32 PoE ISO.

@labricolenumerique
Copy link

labricolenumerique commented May 7, 2024

I use an Olimex esp32 PoE ISO.

@alainstark Which ds248x board do you use as an i²C <==> to 1-wire bus adapter?

@martijnbuts
Copy link

I searched for the chip but i only find the chip itself, not a board. I am interested in testing because of the following:

Internal factory trimmed timers relieve the system host processor from generating time-critical 1-Wire waveforms, supporting both standard and Overdrive 1-Wire communication speeds.
https://www.analog.com/en/products/ds2482-100.html

I have a ESP32-S3 with a lot of sensors and also a modbus connectection and when I add the ds18b20 I get some strange problems. When I use the ds18b20 without the other sensors and modbus connection it works good.
I would like tot test if the ds248x board solve the problem based on the information from the datasheet.

@alainstark
Copy link
Author

This component is working with many I²C to 1-wire : ds2482-100, ds2482-800

@martijnbuts
Copy link

This component is working with many I²C to 1-wire : ds2482-100, ds2482-800

Where did you order the ds2482-100 or ds2482-800?

@alainstark
Copy link
Author

I use this breakout board with this I²C level shifter.

@lboue
Copy link
Contributor

lboue commented May 7, 2024

I noticed other chips in Analog Devices website:

  • DS2484: Single-Channel 1-Wire Master with Adjustable Timing and Sleep Mode
    • Best-in-Class Integrated 1-Wire Line Driver Facilitates Protocol Conversion Between I2C Host and 1-Wire Slave Network
  • DS28E17: - 1-Wire-to-I2C Master Bridge: Extend I2C Slave Peripheral Communication Distance up to 100m

Do you know what the main difference is between the DS2482 and these other references?

CODEOWNERS = ["@alainstark"]

MULTI_CONF = True
AUTO_LOAD = ["sensor"]
Copy link
Member

Choose a reason for hiding this comment

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

Please move all of the sensor code into a sensor directory so that the parent component does not rely on the sensor headers.

Suggested change
AUTO_LOAD = ["sensor"]

Copy link
Author

Choose a reason for hiding this comment

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

Ok I have make the change but I am a poor git user.

$ git status
On branch dev
Your branch is up to date with 'origin/dev'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   CODEOWNERS
	modified:   esphome/components/ds248x/__init__.py
	modified:   esphome/components/ds248x/ds248x.cpp
	modified:   esphome/components/ds248x/ds248x.h
	renamed:    esphome/components/ds248x/sensor.py -> esphome/components/ds248x/sensor/__init__.py
	new file:   esphome/components/ds248x/sensor/ds248x_temperature_sensor.cpp
	new file:   esphome/components/ds248x/sensor/ds248x_temperature_sensor.h

but the commit failed :

$ git commit -m "create sensor directory and restructure"
black....................................................................Passed
flake8...................................................................Passed
Don't commit to branch...................................................Failed
- hook id: no-commit-to-branch
- exit code: 1
pyupgrade................................................................Passed

Can you help me please ?

Copy link
Author

Choose a reason for hiding this comment

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

Ok I used github web interface to change my code.

Copy link
Member

Choose a reason for hiding this comment

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

You should be doing your work on a new branch inside your fork, not the dev branch.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry but as said, I'm a beginner with git. What should I do now?

@esphome esphome bot marked this pull request as draft May 8, 2024 00:04
@esphome
Copy link

esphome bot commented May 8, 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.

@lboue
Copy link
Contributor

lboue commented May 8, 2024

I noticed other chips in Analog Devices website:

  • DS2484: Single-Channel 1-Wire Master with Adjustable Timing and Sleep Mode

    • Best-in-Class Integrated 1-Wire Line Driver Facilitates Protocol Conversion Between I2C Host and 1-Wire Slave Network
  • DS28E17: - 1-Wire-to-I2C Master Bridge: Extend I2C Slave Peripheral Communication Distance up to 100m

Do you know what the main difference is between the DS2482 and these other references?

I started a discussion about that topic: [One-Wire] I²C Master to 1-wire bus slave adapter #6699

Add folder sensor and restructure
Add sensor folder and restructure
Add sensor folder and restructure
Add sensor folder and restructure
Add sensor forder and restructure
Add sensor folder and restructure
Add sensor folder and restructure
@alainstark alainstark requested a review from jesserockz May 9, 2024 19:58
@alainstark
Copy link
Author

Excuse me but I don't know what I should do.
Maybe I just have to wait but I'm asking the question because @jesserockz tells me that I should have created a new branch for restructuring the code but I did it in the dev branch and I don't know how to go back.
On the other hand, there is the automatic code check which indicates an error :
Run script/ci-custom: CODEOWNERS file is not up to date.
So I thought I had to add myself to this file which is at the root but again I think I did it wrong.
Suddenly, I no longer dare to do anything except wait for things to change.
Thank you in advance for your help.

@martijnbuts
Copy link

I would suggest to ask it on the esphome discord, i just recieved the ds2482-100 and i hope this pr got merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants