1
0
mirror of https://github.com/esphome/esphome.git synced 2025-02-20 20:08:20 +00:00
kahrendt 6ecf4ecac6
FS3000 sensor (#4502)
* Add support for FS3000 sensor.

* add fs3000 to test yaml

* Clean up code with clang.

* Clean up sensor.py file.

* Update CODEOWNERS file.

* Apply suggestions from code review regarding sensor.py

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>

* Apply suggestions from code review for basic issues regarding C++ code

- removed unnecessary default for FS3000Model
- use "this->" before any sensor update

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>

* Move model setup to overall setup function.

* Remove unneeded CONF_ID from sensor.py

* Run clang-format

* Move set_model code to header file now that it is simplified

* Update fs3000.h

---------

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2023-03-07 04:25:14 +00:00

51 lines
1.2 KiB
Python

# initially based off of TMP117 component
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import i2c, sensor
from esphome.const import (
CONF_MODEL,
DEVICE_CLASS_WIND_SPEED,
STATE_CLASS_MEASUREMENT,
)
DEPENDENCIES = ["i2c"]
CODEOWNERS = ["@kahrendt"]
fs3000_ns = cg.esphome_ns.namespace("fs3000")
FS3000Model = fs3000_ns.enum("MODEL")
FS3000_MODEL_OPTIONS = {
"1005": FS3000Model.FIVE,
"1015": FS3000Model.FIFTEEN,
}
FS3000Component = fs3000_ns.class_(
"FS3000Component", cg.PollingComponent, i2c.I2CDevice, sensor.Sensor
)
CONFIG_SCHEMA = (
sensor.sensor_schema(
FS3000Component,
unit_of_measurement="m/s",
accuracy_decimals=2,
device_class=DEVICE_CLASS_WIND_SPEED,
state_class=STATE_CLASS_MEASUREMENT,
)
.extend(
{
cv.Required(CONF_MODEL): cv.enum(FS3000_MODEL_OPTIONS, lower=True),
}
)
.extend(cv.polling_component_schema("60s"))
.extend(i2c.i2c_device_schema(0x28))
)
async def to_code(config):
var = await sensor.new_sensor(config)
await cg.register_component(var, config)
await i2c.register_i2c_device(var, config)
cg.add(var.set_model(config[CONF_MODEL]))