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
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
1e3655a
Create __init__.py
alainstark Apr 22, 2024
524dc67
Create sensor.py
alainstark Apr 22, 2024
fe39f28
Create ds248x.h
alainstark Apr 22, 2024
4be59c1
Create ds248x.cpp
alainstark Apr 22, 2024
18d6b3e
Update ds248x.h
alainstark Apr 22, 2024
6a74998
Update sensor.py
alainstark Apr 23, 2024
604325e
Update __init__.py
alainstark Apr 23, 2024
74cd8ac
Update __init__.py
alainstark Apr 23, 2024
51f3195
Update __init__.py
alainstark Apr 23, 2024
b90f22a
Update ds248x.h
alainstark Apr 23, 2024
1d72e61
Create test.esp32.yaml
alainstark Apr 23, 2024
a47ce74
Create test.esp32-c3-idf.yaml
alainstark Apr 23, 2024
2a76cab
Create test.esp32-c3.yaml
alainstark Apr 23, 2024
da53326
Create test.esp32-idf.yaml
alainstark Apr 23, 2024
d9bd32b
Create test.esp8266.yaml
alainstark Apr 23, 2024
c4f653b
Create test.rp2040.yaml
alainstark Apr 23, 2024
902b8f7
Update __init__.py
alainstark Apr 23, 2024
d4a922c
Update __init__.py
alainstark Apr 23, 2024
a20be88
Update __init__.py
alainstark Apr 23, 2024
808b87d
Update __init__.py
alainstark Apr 23, 2024
342f92b
Update test.esp32-c3.yaml
alainstark Apr 23, 2024
996f453
Update test.esp32-c3-idf.yaml
alainstark Apr 23, 2024
858f5ea
Update ds248x.h
alainstark Apr 23, 2024
d0c7709
Update ds248x.cpp
alainstark Apr 23, 2024
fc219f1
Update ds248x.h
alainstark Apr 23, 2024
cb82bed
Update ds248x.cpp
alainstark Apr 23, 2024
bfe072f
Update ds248x.cpp
alainstark Apr 23, 2024
cee308a
Update ds248x.cpp
alainstark Apr 23, 2024
46918f6
Update ds248x.cpp
alainstark Apr 23, 2024
2948591
Update ds248x.cpp
alainstark Apr 23, 2024
49cfaab
Update ds248x.cpp
alainstark Apr 24, 2024
b024c53
Update ds248x.h
alainstark Apr 24, 2024
13161b1
Update ds248x.cpp
alainstark Apr 24, 2024
dd5f076
Update ds248x.cpp
alainstark Apr 24, 2024
4de9b83
Update ds248x.cpp
alainstark Apr 24, 2024
80d1333
Update ds248x.cpp
alainstark Apr 24, 2024
9bfe338
Update __init__.py
alainstark Apr 25, 2024
f4474ab
Update __init__.py
alainstark Apr 25, 2024
d51c5d2
Update __init__.py
alainstark Apr 26, 2024
7fc73c7
Create __init__.py
alainstark May 9, 2024
4740759
Create ds248x_temperature_sensor.h
alainstark May 9, 2024
19cd5e9
Create ds248x_temperature_sensor.cpp
alainstark May 9, 2024
4924478
Delete esphome/components/ds248x/sensor.py
alainstark May 9, 2024
877c7af
Update __init__.py
alainstark May 9, 2024
8a03ddc
Update ds248x.cpp
alainstark May 9, 2024
0a6698d
Update ds248x.h
alainstark May 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
61 changes: 61 additions & 0 deletions esphome/components/ds248x/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import pins
from esphome.const import CONF_ID, CONF_SLEEP_PIN, CONF_TYPE
from esphome.components import i2c

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?

DEPENDENCIES = ["i2c"]

CONF_BUS_SLEEP = "bus_sleep"
CONF_HUB_SLEEP = "hub_sleep"
CONF_ACTIVE_PULLUP = "active_pullup"
CONF_STRONG_PULLUP = "strong_pullup"

ds248x_ns = cg.esphome_ns.namespace("ds248x")
DS248xComponent = ds248x_ns.class_(
"DS248xComponent", cg.PollingComponent, i2c.I2CDevice
)

ds248xType = ds248x_ns.enum("DS248xType", is_class=True)

DS248X_TYPES = {
"ds2482-100": ds248xType.DS2482_100,
"ds2482-800": ds248xType.DS2482_800,
}


CONFIG_SCHEMA = (
cv.Schema(
{
cv.GenerateID(): cv.declare_id(DS248xComponent),
cv.Required(CONF_TYPE): cv.enum(DS248X_TYPES, lower=True),
cv.Optional(CONF_SLEEP_PIN): pins.internal_gpio_output_pin_schema,
cv.Optional(CONF_BUS_SLEEP, default=False): cv.boolean,
cv.Optional(CONF_HUB_SLEEP, default=False): cv.boolean,
cv.Optional(CONF_ACTIVE_PULLUP, default=False): cv.boolean,
cv.Optional(CONF_STRONG_PULLUP, default=False): cv.boolean,
}
)
.extend(cv.polling_component_schema("60s"))
.extend(i2c.i2c_device_schema(0x18))
)


async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
await i2c.register_i2c_device(var, config)

cg.add(var.set_ds248x_type(config[CONF_TYPE]))
cg.add(var.set_bus_sleep(config[CONF_BUS_SLEEP]))
cg.add(var.set_hub_sleep(config[CONF_HUB_SLEEP]))
cg.add(var.set_active_pullup(config[CONF_ACTIVE_PULLUP]))
cg.add(var.set_strong_pullup(config[CONF_STRONG_PULLUP]))

if CONF_SLEEP_PIN in config:
pin = await cg.gpio_pin_expression(config[CONF_SLEEP_PIN])
cg.add(var.set_sleep_pin(pin))