diff --git a/.github/ISSUE_TEMPLATE/issue.md b/.github/ISSUE_TEMPLATE/issue.md index 91aab54..cbaf748 100644 --- a/.github/ISSUE_TEMPLATE/issue.md +++ b/.github/ISSUE_TEMPLATE/issue.md @@ -4,14 +4,14 @@ about: Create a report to help us improve --- -**Version of the cusom_component** - +**Version of the custom_component** + **Describe the bug** A clear and concise description of what the bug is. **log** - + ``` Add your logs here. ``` \ No newline at end of file diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml deleted file mode 100644 index 0dd3efa..0000000 --- a/.github/release-drafter.yml +++ /dev/null @@ -1,5 +0,0 @@ -branches: dev -template: | - ## Changes - - $CHANGES \ No newline at end of file diff --git a/.github/settings.yml b/.github/settings.yml index 9227fef..83ecf7a 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -10,14 +10,14 @@ repository: allow_rebase_merge: false labels: - name: "Feature Request" - color: fbca04 + color: 'fbca04' - name: "Bug" - color: d73a4a + color: 'd73a4a' - name: "Wont Fix" - color: ffffff + color: 'ffffff' - name: "Enhancement" - color: a2eeef + color: 'a2eeef' - name: "Documentation" - color: 008672 + color: '008672' - name: "Stale" - color: 930191 \ No newline at end of file + color: '930191' \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a7c758f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,65 @@ +language: python +stages: + - linting + - load + - publish + +jobs: + include: + #Linting + - stage: linting + install: pip install pycodestyle + name: "Linting with pycodestyle" + python: "3.6" + script: find . -name \*.py -exec pycodestyle {} + + - stage: linting + install: pip install pydocstyle + name: "Linting with pydocstyle" + python: "3.6" + script: find . -name \*.py -exec pydocstyle {} + + - stage: linting + install: pip install pylint + name: "Linting with pylint" + python: "3.6" + script: find . -name \*.py -exec pylint --disable=F0401,W0613 {} + + - stage: linting + install: pip install pyflakes + name: "Linting with pyflakes" + python: "3.6" + script: find . -name \*.py -exec pyflakes {} + + - stage: linting + install: pip install flake8 + name: "Linting with flake8" + python: "3.6" + script: find . -name \*.py -exec flake8 {} + + + # Load component with Home Assistant + - stage: load + name: "Load component/platform in Home Assistant" + install: pip install homeassistant + python: "3.6" + script: + - hass -c . --daemon + - sleep 60 + - cat ./home-assistant.log + - if grep -q 'ERROR' ./home-assistant.log; then echo "There was an error starting Home Assistant"; exit 1; fi + + # Deploy to Github if all tests pass and change was done on master. + # git commit -m 'message' + # git push + # git tag x.x.x + # git push origin x.x.x + - stage: deploy + name: "Deploy to GitHub" + script: skip + deploy: &releases + provider: releases + overwrite: true + skip_cleanup: true + target_commitish: $TRAVIS_COMMIT + tag_name: $TRAVIS_TAG + name: $TRAVIS_TAG + body: $TRAVIS_COMMIT_MESSAGE + api_key: $GHAPI + on: + tags: true \ No newline at end of file diff --git a/README.md b/README.md index 60b4be6..1f32212 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,12 @@ -# Custom_component for `hassbian-config`. +# Custom_component for `hassbian-config` A custom component which allows you to controll some hassbian-config functions from Home Assistant. -To get started put the contents of`/custom_components/hassbian_config/` -here: `/custom_components/hassbian_config/` +To get started put `/custom_components/hassbian_config.py` +here: `/custom_components/hassbian_config.py` **Example configuration.yaml:** + ```yaml hassbian_config: ``` - -For more example see the [services.yaml](https://github.com/custom-components/hassbian-config/blob/master/custom_components/hassbian_config/services.yaml) file. diff --git a/configuration.yaml b/configuration.yaml new file mode 100644 index 0000000..606c183 --- /dev/null +++ b/configuration.yaml @@ -0,0 +1,10 @@ +## this is used by travis +homeassistant: + name: Home Assistant + latitude: 0 + longitude: 0 + elevation: 0 + unit_system: metric + time_zone: Europe/London + +hassbian_config: \ No newline at end of file diff --git a/custom_components/hassbian_config.py b/custom_components/hassbian_config.py new file mode 100644 index 0000000..7e0ddc4 --- /dev/null +++ b/custom_components/hassbian_config.py @@ -0,0 +1,62 @@ +""" +A component which allows you to controll some hassbian-config functions. + +For more details about this component, please refer to the documentation at +https://github.com/ludeeus/hassbian_config +""" +import logging + +__version__ = '2.0.0' + +REQUIREMENTS = ['pyhassbian==0.0.3'] + +DOMAIN = 'hassbian_config' + +_LOGGER = logging.getLogger(__name__) + +def setup(hass, config): + """Setup the component.""" + import pyhassbian + + def install_suite_service(call): + """Define install service.""" + suite = call.data.get('suite') + dev = call.data.get('dev') + beta = call.data.get('beta') + version = call.data.get('version') + all_suites = pyhassbian.get_suites() + if suite in all_suites: + _LOGGER.info('The suite %s is now beeing installed.', suite) + pyhassbian.manage_suite('install', suite, dev, beta, version) + _LOGGER.info('The suite %s has been installed.', suite) + else: + _LOGGER.error('The suite %s does not exist.', suite) + + def upgrade_suite_service(call): + """Define update service.""" + suite = call.data.get('suite') + dev = call.data.get('dev') + beta = call.data.get('beta') + version = call.data.get('version') + if suite in pyhassbian.get_suites(): + _LOGGER.info('The suite %s is now beeing upgraded.', suite) + pyhassbian.manage_suite('upgrade', suite, dev, beta, version) + _LOGGER.info('The suite %s has been upgraded.', suite) + else: + _LOGGER.error('The suite %s does not exist.', suite) + + def upgrade_os_service(call): + """Define update base OS service.""" + _LOGGER.info('Upgrade of the base OS are starting.') + pyhassbian.os_upgrade() + _LOGGER.info('Upgrade of the base OS are done.') + + + if pyhassbian.is_installed(): + _LOGGER.info('hassbian-config found, registering services.') + hass.services.register(DOMAIN, 'install_suite', install_suite_service) + hass.services.register(DOMAIN, 'upgrade_suite', upgrade_suite_service) + hass.services.register(DOMAIN, 'upgrade_os', upgrade_os_service) + else: + _LOGGER.error('hassbian-config not found...') + return True diff --git a/custom_components/hassbian_config/__init__.py b/custom_components/hassbian_config/__init__.py deleted file mode 100644 index 8ef1829..0000000 --- a/custom_components/hassbian_config/__init__.py +++ /dev/null @@ -1,61 +0,0 @@ -""" -A component which allows you to controll some hassbian-config functions from Home Assistant. -For more details about this component, please refer to the documentation at -https://github.com/ludeeus/hassbian-config_custom_component -""" -__version__ = '1.0.4' - -import subprocess -import logging -from pathlib import Path -from homeassistant.core import callback - -DOMAIN = 'hassbian_config' - -INSTALL_SUITES = ('appdaemon', 'cloud9', 'hue', 'mosquitto', 'samba', 'tradfri') -UPGRADE_SUITES = ('appdaemon', 'cloud9', 'hassbian-script', 'homeassistant') - -ATTR_SUITE = 'suite' -ATTR_BETA = 'beta' -ATTR_DEV = 'dev' -ATTR_VERSION = 'version' -HASSBIAN_CONFIG_DIR = Path("/usr/local/bin/hassbian-config") - -_LOGGER = logging.getLogger(__name__) - -def setup(hass, config): - def install_suite_service(call): - suite = call.data.get(ATTR_SUITE) - if suite in INSTALL_SUITES: - _LOGGER.info('The suite %s is now beeing installed.', suite) - subprocess.call(['sudo', 'hassbian-config', 'install', suite, '--accept']) - hass.components.persistent_notification.create('The suite **'+suite+'** has been installed.', 'HASSBIAN-CONFIG') - else: - _LOGGER.error('The suite %s does not exist, or can not be installed automatically.', suite) - def upgrade_suite_service(call): - suite = call.data.get(ATTR_SUITE) - dev = call.data.get(ATTR_DEV) - beta = call.data.get(ATTR_BETA) - version = call.data.get(ATTR_VERSION) - if suite in UPGRADE_SUITES: - _LOGGER.info('The suite %s is now beeing upgraded.', suite) - if (dev == True) or (dev == "true"): - subprocess.run(['sudo', 'hassbian-config', 'upgrade', suite, '--accept', '--dev']) - elif (beta == True) or (beta == "true"): - subprocess.run(['sudo', 'hassbian-config', 'upgrade', suite, '--accept', '--beta']) - else: - if (version == None): - subprocess.run(['sudo', 'hassbian-config', 'upgrade', suite, '--accept']) - else: - subprocess.run(['sudo', 'hassbian-config', 'upgrade', suite+'='+str(version), '--accept']) - hass.components.persistent_notification.create('The suite **'+suite+'** has been upgraded.', 'HASSBIAN-CONFIG') - else: - _LOGGER.error('The suite %s does not exist, or can not be upgraded automatically.', suite) - - if HASSBIAN_CONFIG_DIR.is_file(): - _LOGGER.info('hassbian-config found, registering services.') - hass.services.register(DOMAIN, 'install_suite', install_suite_service) - hass.services.register(DOMAIN, 'upgrade_suite', upgrade_suite_service) - else: - _LOGGER.error('hassbian-config not found, services will not be registered...') - return True \ No newline at end of file diff --git a/custom_components/hassbian_config/services.yaml b/custom_components/hassbian_config/services.yaml deleted file mode 100644 index b8487ec..0000000 --- a/custom_components/hassbian_config/services.yaml +++ /dev/null @@ -1,21 +0,0 @@ -install_suite: - description: Installs a suite with hassbian-config. - fields: - suite: - description: 'Can be one of: hue, cloud9, mosquitto, tradfri, samba, appdaemon. [Required]' - example: hue -upgrade_suite: - description: Upgrades a suite with hassbian-config. - fields: - suite: - description: 'Can be one of: appdaemon, cloud9, hassbian-script, homeassistant [Required]' - example: hassbian-script - beta: - description: 'Can be true true or false, defaults to false [Optional]' - example: false - dev: - description: 'Can be true true or false, defaults to false [Optional]' - example: false - version: - description: 'Set target version for homeassistant [Optional]' - example: 0.65.5 \ No newline at end of file