mirror of
https://github.com/geoffdavis/esphome-mitsubishiheatpump
synced 2024-08-30 18:12:13 +00:00
Make this usable as an external_component
Since v1.18.0 esphome supports external components which allow you to use custom components much more easily. https://esphome.io/components/external_components.html
This commit is contained in:
parent
06bc22c025
commit
d15916fbdc
3
.gitignore
vendored
3
.gitignore
vendored
@ -30,3 +30,6 @@
|
|||||||
*.exe
|
*.exe
|
||||||
*.out
|
*.out
|
||||||
*.app
|
*.app
|
||||||
|
|
||||||
|
# Python cache
|
||||||
|
__pycache__
|
||||||
|
46
components/mitsubishi_heatpump/__init__.py
Normal file
46
components/mitsubishi_heatpump/__init__.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import esphome.codegen as cg
|
||||||
|
import esphome.config_validation as cv
|
||||||
|
from esphome.components import climate
|
||||||
|
from esphome.components.logger import HARDWARE_UART_TO_SERIAL
|
||||||
|
from esphome.const import CONF_ID, CONF_HARDWARE_UART, CONF_UPDATE_INTERVAL
|
||||||
|
from esphome.core import CORE, coroutine
|
||||||
|
|
||||||
|
AUTO_LOAD = ["climate"]
|
||||||
|
|
||||||
|
MitsubishiHeatPump = cg.global_ns.class_("MitsubishiHeatPump", climate.Climate, cg.PollingComponent)
|
||||||
|
|
||||||
|
|
||||||
|
def valid_uart(uart):
|
||||||
|
if CORE.is_esp8266:
|
||||||
|
uarts = ["UART0"] # UART1 is tx-only
|
||||||
|
elif CORE.is_esp32:
|
||||||
|
uarts = ["UART0", "UART1", "UART2"]
|
||||||
|
else:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
return cv.one_of(*uarts, upper=True)(uart)
|
||||||
|
|
||||||
|
|
||||||
|
CONFIG_SCHEMA = climate.CLIMATE_SCHEMA.extend(
|
||||||
|
{
|
||||||
|
cv.GenerateID(): cv.declare_id(MitsubishiHeatPump),
|
||||||
|
cv.Optional(CONF_HARDWARE_UART, default="UART0"): valid_uart,
|
||||||
|
|
||||||
|
# If polling interval is greater than 9 seconds, the HeatPump library
|
||||||
|
# reconnects, but doesn't then follow up with our data request.
|
||||||
|
cv.Optional(CONF_UPDATE_INTERVAL, default="500ms"): cv.All(
|
||||||
|
cv.update_interval,
|
||||||
|
cv.Range(max=cv.TimePeriod(milliseconds=9000))
|
||||||
|
),
|
||||||
|
}
|
||||||
|
).extend(cv.COMPONENT_SCHEMA)
|
||||||
|
|
||||||
|
|
||||||
|
@coroutine
|
||||||
|
def to_code(config):
|
||||||
|
serial = HARDWARE_UART_TO_SERIAL[config[CONF_HARDWARE_UART]]
|
||||||
|
var = cg.new_Pvariable(config[CONF_ID], cg.RawExpression(f'&{serial}'))
|
||||||
|
yield cg.register_component(var, config)
|
||||||
|
yield climate.register_climate(var, config)
|
||||||
|
cg.add_library("https://github.com/SwiCago/HeatPump", None)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user