Skip to content

Design proposal for V2 of ESPHome components #10

@kpfleming

Description

@kpfleming

I mentioned to Sam recently that I'm motivated (and have time) to do some work on a redesign of the ESPHome components. I've worked on a number of other ESPHome components and contributed to various parts of the platform, and I also hang out in the 'dev' Discord channel so I'm familiar with the types of things that the core team likes and dislikes. While it may never be useful for the MITP components to be incorporated upstream, I'd personally like to see them be built in a way that they could be.

My goals for this redesign are:

  1. Ensure that the Python (configuration) and C++ (implementation) code is internally consistent (naming, interfaces, etc.) and broken into logical pieces which can be reviewed on their own.
  2. Remove the diagnostic sensors from the climate component since the core team prefers the climate component to be focused on its own functionality; these sensors should be made available by a separate component.
  3. Remove bridging from the climate component for the same reasons; this functionality should be made available by a dedicated component.
  4. Support a wider variety of configuration styles - for example some users may want to only monitor their heatpump/thermostat and not have a 'climate' component at all (avoiding any risk of setpoints being changed by HA or ESPHome).
  5. Provide a mechanism to support my future 'mitp-failsafe' hardware design, where the heatpump and thermostat are not connected directly to ESP UARTs but instead are proxied by another MCU.
  6. Provide a mechanism to support integration testing by incorporating simulated heatpumps/thermostats into the configuration.

MITP 'links'

The lowest layer of the configuration and implementation are MITP 'links' - communications channels where MITP packets are sent and received between the ESP and some other device.

An example configuration for MITP-over-UART could be:

mitp_link:
  - id: hp_link
    platform: mitp_link_uart
    uart: hp_uart
  - id: th_link
    platform: mitp_link_uart
    uart: th_uart

This would create two mitp_link components which operate by sending and receiving ITP packets; in the C++ code the interface to these components would be the packets defined in the itp-packet library. Since these are UART links, they would handle framing, encoding, decoding, etc. for the ITP-over-UART protocol.

Alternative implementations of mitp_link would have the same C++ interface but use a different implementation. Examples could include 'mock' components which simulate a heatpump or thermostat; 'TCP' components which support links over network connections; and my 'failsafe' component which would expose two links over one UART, using Protocol Buffers for the packet communication.

MITP 'devices'

The next layer are devices: heatpumps and thermostats.

An example configuration for these could be:

mitp_device:
  - id: hp
    type: heatpump
    mitp_link_id: hp_link
    (fan modes, operating modes, etc. go here)
  - id: th
    type: thermostat
    enhanced_mhk: true/false
    time_id: (id of time component, auto-detected in most cases)

The various sensors which are not related to the climate component would be exposed by these device components: It is possible during the implementation that it may be necessary to make separate mitp_heatpump and mitp_thermostat components instead of an mitp_device component with a type attribute.

MITP 'bridging'

If the user wants to use both a heatpump and thermostat, and bridge between them, they'd use a configuration like this:

mitp_bridge:
  - id: bridge
    mitp_heatpump_id: (auto-detected in most cases)
    mitp_thermostat_id: (auto-detected in most cases)
    (any bridge-specific attributes go here)

MITP 'climate'

Finally, there is the climate component. It would be able to operate off of either a heatpump or a bridge.

climate:
  - id: hp_direct
    platform: mitp_device (or mitp_heatpump)
    mitp_heatpump_id: (auto-detected in most cases)
    (climate component attributes go here)
  - id: bridged
    platform: mitp_bridge
    mitp_bridge_id: (auto-detected in most cases)
    (climate component attributes go here)

MITP 'sensor', 'binary_sensor', 'text_sensor', 'button', 'select'

All of these would look as they do today, except the platform names would change as they'd reference the new components.

Implementation plan

I would do this work in my own fork of the ESPHome core repository, lifting code from the esphome-components repository in this organization as needed. Initially I'd focus on the Python code, getting the schemas built and parsed properly, with very minimal to_code implementations that just instantiate the proper C++ classes but without any implementation code in those classes. Once that is ready for review I'll ask for testers and feedback, to get more people building example configurations that meet their needs and ensuring that the Python code will accept them.

Assuming that phase goes well, I'd then start copying around the C++ code into the new components, starting at the bottom layer and working my way up. I'll use my own systems for testing (carefully, of course!) and when it's ready for beta testing by others I'll ask for testers again.

Ongoing support

I'm happy to commit to being around for the long-term to support this work, as long as my health and other personal circumstances permit it. I've got a very long history in the open source community and have a number of my own projects that I support (including an ESPHome component for publishing data to InfluxDB) so I know what's required and I plan to do it for as long as I can.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions