summary refs log tree commit diff
path: root/pkgs/tools/misc/esphome/default.nix
blob: d2b84b285339675f58e6a202ed05c7f91cb9f6da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
{ lib
, python3
, fetchFromGitHub
, platformio
, esptool
, git
}:

python3.pkgs.buildPythonApplication rec {
  pname = "esphome";
  version = "1.17.1";

  src = fetchFromGitHub {
    owner = pname;
    repo = pname;
    rev = "v${version}";
    sha256 = "0483glwi155ca1wnffwhmwn17d7kwk4hjwmckb8zs197rfqmb55v";
  };

  postPatch = ''
    # remove all version pinning (E.g tornado==5.1.1 -> tornado)
    sed -i -e "s/==[0-9.]*//" requirements.txt

    # drop coverage testing
    sed -i '/--cov/d' pytest.ini

    # migrate use of hypothesis internals to be compatible with hypothesis>=5.32.1
    # https://github.com/esphome/issues/issues/2021
    substituteInPlace tests/unit_tests/strategies.py --replace \
      "@st.defines_strategy_with_reusable_values" \
      "@st.defines_strategy(force_reusable_values=True)"
  '';

  # Remove esptool and platformio from requirements
  ESPHOME_USE_SUBPROCESS = "";

  # esphome has optional dependencies it does not declare, they are
  # loaded when certain config blocks are used, like `font`, `image`
  # or `animation`.
  # They have validation functions like:
  # - validate_cryptography_installed
  # - validate_pillow_installed
  propagatedBuildInputs = with python3.pkgs; [
    click
    colorama
    cryptography
    ifaddr
    paho-mqtt
    pillow
    protobuf
    pyserial
    pyyaml
    tornado
    tzlocal
    voluptuous
  ];

  makeWrapperArgs = [
    # platformio is used in esphomeyaml/platformio_api.py
    # esptool is used in esphomeyaml/__main__.py
    # git is used in esphomeyaml/writer.py
    "--prefix PATH : ${lib.makeBinPath [ platformio esptool git ]}"
    "--set ESPHOME_USE_SUBPROCESS ''"
  ];

  checkInputs = with python3.pkgs; [
    hypothesis
    mock
    pytest-mock
    pytestCheckHook
  ];

  postCheck = ''
    $out/bin/esphome --help > /dev/null
  '';

  meta = with lib; {
    description = "Make creating custom firmwares for ESP32/ESP8266 super easy";
    homepage = "https://esphome.io/";
    license = with licenses; [
      mit # The C++/runtime codebase of the ESPHome project (file extensions .c, .cpp, .h, .hpp, .tcc, .ino)
      gpl3Only # The python codebase and all other parts of this codebase
    ];
    maintainers = with maintainers; [ globin elseym hexa ];
  };
}