ginkage / MHI-AC-Ctrl-ESPHome

ESPHome integration for MHI-AC-Ctrl project
MIT License
95 stars 35 forks source link

Cleanup config files #74

Closed RoboMagus closed 3 months ago

RoboMagus commented 5 months ago

This PR moves all entities related to the MHI-AC-Ctrl into the conf/*.yaml files. And any unrelated components out of them, and into the main lr_mhi_ac_ctrl.yaml config file.

These changes make it easier for users to include these config files in their own main device configuration without having to manually add the other entities such as the defrost and compressor protection status. Entities unrelated to the MHI-AC-Ctrl (e.g. WiFi stats) have been moved out of these config files as they are not related to the core functionality that is provided by this component.

Top level inclusion is now done using packages (instead of the direct inclusion: <<: !include), which allows merging of e.g. the sensors: defined in multiple files when including.

Re-structuring the config files like this makes it easier for users to include this repo as a Submodule in their EspHome config directories without the need to make in-repo changes or to copy-paste most of the config files into their own. This keeps the Submodule clean and easier to stay up to date with any future changes.

This also greatly simplifies the main config file. ( mine: )


substitutions:
  # Unique device ID in HA
  deviceid: "mhi_ac_ctrl"
  # Unique device name in HA (sensor names will be prefixed by this name)
  devicename: "MHI-AC-Ctrl"

  friendly_name: ${devicename}
  hostname: "mhi-ac-ctrl"

packages:
  # Basic common boilerplate configuration:
  common: !include common/base_config.yaml
  # Use new 33B framesize to allow for Vanes control
  mhi-ac-ctrl: !include SubModules/MHI-AC-Ctrl-ESPHome/conf/large_framesize.yaml

esp8266:
  board: d1_mini

esphome:
  platformio_options:
    # Run CPU at 160Mhz to fix mhi_ac_ctrl_core.loop error: -2
    board_build.f_cpu: 160000000L
  includes:
    # https://github.com/ginkage/MHI-AC-Ctrl-ESPHome
    - SubModules/MHI-AC-Ctrl-ESPHome/mhi_ac_ctrl.h
    - SubModules/MHI-AC-Ctrl-ESPHome/MHI-AC-Ctrl-core.h
    - SubModules/MHI-AC-Ctrl-ESPHome/MHI-AC-Ctrl-core.cpp

api:
  services:
    # Call the set_vanes service from HA to set the vane position
    # Needed because the ESPHome Climate class does not support this natively
    # Possible values: 1-4: static positions, 5: swing, 0: unknown
    - service: set_vanes
      variables:
        value: int
      then:
        - lambda: |-
            return ((MhiAcCtrl*)id(${deviceid}))->set_vanes(value);
RobertJansen1 commented 3 months ago

With some mis clicks from my side, i made this from a small merge conflict to a giant mess... resolved it, tested and ready to merge