defaults = {
    'apt': {
        'packages': {
            'autoconf': {},
            'bluez':  {},
            'build-essential': {},
            'libffi-dev': {},
            'libjpeg-dev': {},
            'libopenjp2-7': {},
            'libssl-dev': {},
            'libtiff6': {},
            'libturbojpeg0-dev': {},
            'python3-packaging': {},
            'tzdata': {},
            'zlib1g-dev': {},
        },
    },
    'backups': {
        'paths': {
            '/opt/homeassistant',
            '/var/opt/homeassistant',
        },
    },
}


@metadata_reactor.provides(
    'icinga2_api/homeassistant/services',
)
def icinga_check_for_new_release(metadata):
    return {
        'icinga2_api': {
            'homeassistant': {
                'services': {
                    'HOMEASSISTANT UPDATE': {
                        'check_interval': '60m',
                        'command_on_monitored_host': '/usr/local/share/icinga/plugins/check_homeassistant_update',
                        'vars.notification.mail': True,
                        'vars.sshmon_timeout': 20,
                    },
                },
            },
        },
    }


@metadata_reactor.provides(
    'nginx/vhosts/homeassistant',
)
def nginx(metadata):
    if not node.has_bundle('nginx'):
        raise DoNotRunAgain

    return {
        'nginx': {
            'vhosts': {
                'homeassistant': {
                    'domain': metadata.get('homeassistant/domain'),
                    'website_check_path': '/auth/authorize',
                    'website_check_string': 'Home Assistant',
                    'locations': {
                        '/': {
                            'target': 'http://127.0.0.1:8123',
                            'websockets': True,
                        },
                    },
                },
            },
        },
    }