name: zwavejs2mqtt
base: core20
version: 'v6.1.0'
summary: Fully configurable Zwave to MQTT Gateway and Control Panel.
description: "** Fully configurable Zwave to MQTT Gateway and Control Panel**\n\n- Zwave to Mqtt Gateway: Configure how nodes and nodes values are \n  mapped between the two protocols\n- Secured: Supports HTTPS and users authentication\n- Control Panel UI: Directly control all your nodes and their \n  values from the UI, some of control panel features:\n    - Nodes management: check all nodes discovered in the z-wave \n      network and manage their values\n    - Firmware updates: update devices firmware, just select the \n      controller action _Begin Firmware Update_ and upload the \n      firmware file\n    - Groups associations: add/edit nodes associations\n    - Full zwave-js APIs support\n- Custom scenes management: create scenes and trigger them by using\n  MQTT apis (also supports timeouts)\n- Log debug in UI: See debug logs directly from the UI\n- Store directory management: all files are stored in store folder, \n  you can download/edit files inside this folder directly from the UI\n- Network graph: see how nodes are communicating with the controller,\n  useful for diagnostics purposes\n- Home Assistant integration: you can use official Zwavejs integration \n  by enabling zwavejs server or use integrated MQTT discovery integration\n\n**Channels in `latest`**\n\nThis is how we use the different of channels in the `latest` track, \nto give the user a chance to choose how often they want updates.\n\n- `latest/stable`: Latest version of the last *major* release. Will\n  only update once per major release and most likely by the end of\n  that release cycle. E.g when there is a new version `b.a.a` then\n  version `a.b.c` will be will be available.\n\n- `latest/candidate`:  Latest minor or patch release of latest major\n  release. E.g when version `a.b.c` changes to `a.b.d` or `a.c.a`, then\n  version `a.b.d` or `a.c.a` will be available. Consider this rolling\n  releases.\n\n- `latest/edge` and `latest/edge/dev`: Every build (including tests) \\n  might be pushed to these channels.\n"
grade: stable
confinement: strict
license: MIT
assumes:
  - command-chain
architectures:
  - build-on: amd64
  - build-on: arm64
  - build-on: armhf
apps:
  zwavejs2mqtt:
    daemon: simple
    restart-condition: always
    environment:
      STORE_DIR: $SNAP_DATA
      ZWAVEJS_EXTERNAL_CONFIG: $SNAP_DATA/.ext-config
      DAEMONIZED: 1
    command: bin/yarn start
    command-chain:
      - helper/env-wrapper
    plugs:
      - network
      - network-bind
      - raw-usb
      - serial-port
      - hardware-observe
  exec:
    environment:
      STORE_DIR: $SNAP_DATA
      ZWAVEJS_EXTERNAL_CONFIG: $SNAP_DATA/.ext-config
    command: bin/yarn --cwd $SNAP/lib/node_modules/zwavejs2mqtt start
    command-chain:
      - helper/env-wrapper
    plugs:
      - network
      - network-bind
      - raw-usb
      - serial-port
      - hardware-observe
  help:
    command: helper/env-wrapper --help
  enable:
    command: bin/daemonize
  disable:
    command: bin/de-daemonize
  restart:
    command: bin/restart
layout:
  /usr/local/share/.cache/yarn:
    bind: $SNAP/.cache/yarn
  /usr/local/share/.yarn:
    symlink: $SNAP/lib/node_modules
parts:
  zwavejs2mqtt:
    after: [yarn]
    plugin: dump
    source: https://github.com/zwave-js/zwavejs2mqtt.git
    #source-branch: "master"
    source-tag: $SNAPCRAFT_PROJECT_VERSION
    build-packages:
      - gcc
      - build-essential
      - jq
    override-build: |
      set -x
      # Used when testing an unreleased version of Z-wavejs
      sed -i 's/"zwave-js".*$/"zwave-js"\: "8.9.0-beta.2"/g' ${SNAPCRAFT_PART_BUILD}/package.json
      if [ -n "${http_proxy-}" ]; then
        yarn config set httpProxy "${http_proxy}"
      fi
      if [ -n "${https_proxy-}" ]; then
        yarn config set httpsProxy "${https_proxy}"
      fi
      yarn set version berry
      yarn install \
        && yarn run build \
        && yarn remove $(cat "${SNAPCRAFT_PART_BUILD}/package.json" | jq -r '.devDependencies | keys | join(" ")') \
        && mkdir -p "${SNAPCRAFT_PART_INSTALL}/lib/node_modules" \
        && cp --archive --link --no-dereference "${SNAPCRAFT_PART_BUILD}" \
          "${SNAPCRAFT_PART_INSTALL}/lib/node_modules/zwavejs2mqtt" \
    organize:
      lib/node_modules/zwavejs2mqtt/dist: lib/node_modules/zwavejs2mqtt/server/dist
      lib/node_modules/zwavejs2mqtt/views: lib/node_modules/zwavejs2mqtt/server/views
    filesets:
      zwavejs2mqtt-include:
        - lib/node_modules/zwavejs2mqtt/.git
        - lib/node_modules/zwavejs2mqtt/*.md
        - lib/node_modules/zwavejs2mqtt/LICENSE
        - lib/node_modules/zwavejs2mqtt/node_modules
        - lib/node_modules/zwavejs2mqtt/server
        - lib/node_modules/zwavejs2mqtt/package.json
        - lib/node_modules/zwavejs2mqtt/.yarn
        - lib/node_modules/zwavejs2mqtt/yarn.lock
        - lib/node_modules/zwavejs2mqtt/.yarnrc.yml
    stage:
      - $zwavejs2mqtt-include
  dependencies:
    plugin: nil
    stage-snaps:
      - jq
      - yq
    stage-packages:
      - git
      - udev
      - rsync
  nodejs:
    plugin: dump
    source:
      - on amd64: https://nodejs.org/dist/v16.13.0/node-v16.13.0-linux-x64.tar.gz
      - on arm64: https://nodejs.org/dist/v16.13.0/node-v16.13.0-linux-arm64.tar.gz
      - on armhf: https://nodejs.org/dist/v16.13.0/node-v16.13.0-linux-armv7l.tar.gz
    stage-packages:
      - on armhf:
          - libatomic1
    organize:
      '*.md': nodejs/
      LICENSE: nodejs/
    prime:
      - -include
      - -share
  yarn:
    after: [nodejs]
    plugin: nil
    override-build: |
      npm install yarn
      snapcraftctl build
      cp -r $SNAPCRAFT_PART_BUILD/* $SNAPCRAFT_PART_INSTALL
    organize:
      node_modules/yarn: lib/node_modules/yarn
    stage:
      - lib/node_modules/yarn
    override-stage: |
      snapcraftctl stage 
      PWD=$(pwd)
      cd $SNAPCRAFT_STAGE/bin
      ln -sf ../lib/node_modules/yarn/bin/yarn yarn
      cd "${PWD}"
    prime:
      - lib/node_modules/yarn
      - bin/yarn
  local:
    plugin: dump
    source: src/
    stage-packages:
      - uuid
    organize:
      hooks: snap/hooks