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

Husb238 USB PD controller #6693

Open
wants to merge 22 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ esphome/components/host/* @esphome/core
esphome/components/hrxl_maxsonar_wr/* @netmikey
esphome/components/hte501/* @Stock-M
esphome/components/htu31d/* @betterengineering
esphome/components/husb238/* @latonita
esphome/components/hydreon_rgxx/* @functionpointer
esphome/components/hyt271/* @Philippe12
esphome/components/i2c/* @esphome/core
Expand Down
30 changes: 30 additions & 0 deletions esphome/components/husb238/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import i2c
from esphome.const import CONF_ID

DEPENDENCIES = ["i2c"]
AUTO_LOAD = ["sensor", "binary_sensor", "text_sensor"]

CONF_HUSB238_ID = "husb238_id"

husb238_ns = cg.esphome_ns.namespace("husb238")
Husb238Component = husb238_ns.class_(
"Husb238Component", cg.PollingComponent, i2c.I2CDevice
)

CONFIG_SCHEMA = cv.Schema(
cv.Schema(
{
cv.GenerateID(): cv.declare_id(Husb238Component),
}
)
.extend(cv.polling_component_schema("10s"))
.extend(i2c.i2c_device_schema(0x08))
)


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)
45 changes: 45 additions & 0 deletions esphome/components/husb238/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import binary_sensor
from esphome.const import CONF_NAME, ENTITY_CATEGORY_DIAGNOSTIC
from . import Husb238Component, CONF_HUSB238_ID

CODEOWNERS = ["@latonita"]
DEPENDENCIES = ["husb238"]

CONF_ATTACHED = "attached"
CONF_CC_DIRECTION = "cc_direction"

TYPES = [CONF_ATTACHED]

CONFIG_SCHEMA = cv.All(
cv.Schema(
{
cv.GenerateID(CONF_HUSB238_ID): cv.use_id(Husb238Component),
cv.Optional(CONF_ATTACHED): cv.maybe_simple_value(
binary_sensor.binary_sensor_schema(
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
key=CONF_NAME,
),
cv.Optional(CONF_CC_DIRECTION): cv.maybe_simple_value(
binary_sensor.binary_sensor_schema(
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
),
key=CONF_NAME,
),
}
).extend(cv.COMPONENT_SCHEMA)
)


async def setup_conf(config, key, hub):
if sensor_config := config.get(key):
var = await binary_sensor.new_binary_sensor(sensor_config)
cg.add(getattr(hub, f"set_{key}_binary_sensor")(var))


async def to_code(config):
hub = await cg.get_variable(config[CONF_HUSB238_ID])
for key in TYPES:
await setup_conf(config, key, hub)