name: home-assistant-snap
version: '2021.8.5'
summary: Open source home automation that puts local control and privacy first
description: |
  Home Assistant is a home automation platform running on Python 3. 
  It is able to track and control all devices at home and offer a 
  platform for automating control. 

  Your new installation will be available through your browser at http://localhost:8123/

  Please see official docs: https://git.giaever.org/joachimmg/home-assistant-snap and https://community.home-assistant.io for help on configuration etc.

  See `snap connections home-assistant-snap` for necessary plugs (such as access to USB etc).

  NOTE! Snap will automatically update whenever a new revision of the snap package is available. 
base: core20
grade: stable
confinement: strict
license: Apache-2.0

architectures:
  - build-on: amd64
  - build-on: arm64
  - build-on: armhf
  - build-on: ppc64el

layout:
  /etc/pip.conf:
    bind-file: $SNAP_COMMON/pip.conf
  /etc/openzwave:
    bind: $SNAP/openzwave
  # /etc/ethertypes:
  #   bind-file: $SNAP/etc/ethertypes

plugs:
  bin:
    interface: content
    content: executables
    target: $SNAP/shared-bin

slots:
  components:
    interface: content
    content: components
    write: 
      - $SNAP_DATA/custom_components
  configurations:
    interface: content
    write:
      - $SNAP_DATA

apps:
  home-assistant-snap:
    command: bin/hass --config $SNAP_DATA
    command-chain:
      - bin/plug-bin
    daemon: simple
    environment:
      PIP_USER: 1
    restart-condition: always
    plugs: 
      - bluez
      - network
      - network-bind
      - network-control
      - raw-usb
      - serial-port
      - physical-memory-control
      - removable-media
    slots: 
      - components
  open-localhost:
    command: bin/open-localhost
    plugs:
      - desktop
  check-config:
    plugs: 
      - network
    environment:
      PIP_USER: 1
    command: bin/hass --script check_config --config $SNAP_DATA -i

parts:
  homeassistant:
    plugin: python-wot-plugin
    source: https://github.com/home-assistant/core.git
    source-tag: ${SNAPCRAFT_PROJECT_VERSION}
    python-packages:
      - setuptools
      - wheel
      - Cython
      - pip
    build-packages:
      - python3
      - python3-dev
      - python3-setuptools
      - python3-wheel
      - pkg-config
      - autoconf
      - build-essential
      - cmake
      - cython3
      - ffmpeg
      - libavcodec-dev
      - libavdevice-dev
      - libavfilter-dev
      - libavformat-dev
      - libavresample-dev
      - libavutil-dev
      - libffi-dev
      - libglib2.0-dev
      - libglu1-mesa-dev
      - libgpiod-dev
      - libjpeg-dev
      - libopenzwave1.5-dev
      - libpcap0.8-dev
      - libswresample-dev
      - libssl-dev
      - libswscale-dev
      - libudev-dev
      - libxml2-dev
      - libxslt1-dev
      - zlib1g-dev
    stage-packages:
      - freeglut3
      - ffmpeg
      - libglu1-mesa
      - tcpdump
      - libpcap0.8
      - zlib1g
    stage:
      - -lib/python3.8/site-packages/homeassistant/components/updater
    requirements:
      - requirements_all.txt
    constraints:
      - homeassistant/package_constraints.txt
    override-build: |
      snapcraftctl build
      sed -i 's/include-system-site-packages = false/include-system-site-packages = true/g' $SNAPCRAFT_PART_INSTALL/pyvenv.cfg
  updater:
    after: [homeassistant]
    plugin: dump
    source: ./src/components
    source-type: local
    organize:
      '*': lib/python3.8/site-packages/homeassistant/components/
  bins:
    plugin: dump
    source: ./src/bin
    source-type: local
    organize:
      open-localhost: bin/open-localhost
  hooks:
    plugin: dump
    source: ./src/hooks
    source-type: local
    stage-packages:
      - uuid
    organize:
      install: snap/hooks/install
      configure: snap/hooks/configure
      post-refresh: snap/hooks/post-refresh
      connect-plug-bin: snap/hooks/connect-plug-bin
  config:
    plugin: dump
    source: ./src/config
    source-type: local
    organize:
      plug-bin: bin/plug-bin