commit f686660196b52221283c1edf7223b9a245716828 Author: ludeeus Date: Fri Mar 8 19:17:48 2019 +0100 init diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..6bcce42 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,17 @@ +--- +name: Feature request +about: Suggest an idea for this project + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/issue.md b/.github/ISSUE_TEMPLATE/issue.md new file mode 100644 index 0000000..277703d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/issue.md @@ -0,0 +1,37 @@ +--- +name: Issue +about: Create a report to help us improve + +--- + + + +## Version of the custom_component + + +## Describe the bug +A clear and concise description of what the bug is. + +## `custom_updater` configuration + +```yaml + +# Add configuration here + +``` + +## Debug log + +```text + +Add your logs here. + +``` \ No newline at end of file diff --git a/.github/main.workflow b/.github/main.workflow new file mode 100644 index 0000000..54aef73 --- /dev/null +++ b/.github/main.workflow @@ -0,0 +1,38 @@ +workflow "Trigger: Push to master from admin account" { + on = "push" + resolves = [ + "HA Index" + ] +} + +workflow "Trigger: Push" { + on = "push" + resolves = [ + "Black Code Formatter" + ] +} + + +action "branch-filter" { + uses = "actions/bin/filter@master" + args = "branch master" +} + +action "Access control" { + uses = "ludeeus/actions/accesscontrol@master" + env = { + ACTION_LEVEL = "admin" + } + secrets = ["GITHUB_TOKEN"] +} + +action "HA Index" { + uses = "ludeeus/actions/haindex@master" + secrets = ["GITHUB_TOKEN"] + needs = ["branch-filter", "Access control"] +} + +action "Black Code Formatter" { + uses = "lgeiger/black-action@v1.0.1" + args = "$GITHUB_WORKSPACE --check" +} \ No newline at end of file diff --git a/.github/settings.yml b/.github/settings.yml new file mode 100644 index 0000000..6b75ccc --- /dev/null +++ b/.github/settings.yml @@ -0,0 +1,23 @@ +repository: + private: false + has_issues: true + has_projects: false + has_wiki: false + has_downloads: false + default_branch: master + allow_squash_merge: true + allow_merge_commit: false + allow_rebase_merge: false +labels: + - name: "Feature Request" + color: "fbca04" + - name: "Bug" + color: "b60205" + - name: "Wont Fix" + color: "ffffff" + - name: "Enhancement" + color: a2eeef + - name: "Documentation" + color: "008672" + - name: "Stale" + color: "930191" \ No newline at end of file diff --git a/.github/stale.yml b/.github/stale.yml new file mode 100644 index 0000000..78973bc --- /dev/null +++ b/.github/stale.yml @@ -0,0 +1,16 @@ +# Number of days of inactivity before an issue becomes stale +daysUntilStale: 14 +# Number of days of inactivity before a stale issue is closed +daysUntilClose: 7 +# Issues with these labels will never be considered stale +#exemptLabels: +# - pinned +# - security +# Label to use when marking an issue as stale +staleLabel: Stale +# Comment to post when marking an issue as stale. Set to `false` to disable +markComment: > + This issue has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. +# Comment to post when closing a stale issue. Set to `false` to disable +closeComment: false \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..eadefd3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Joakim Sørensen @ludeeus + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..618f6dd --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +# blueprint + +[![BuyMeCoffee][buymecoffeebedge]][buymecoffee] +[![custom_updater][customupdaterbadge]][customupdater] + +_Component to integrate with [blueprint][blueprint]._ + +**This component will set up the following platforms.** + +Platform | Description +-- | -- +`sensor` | Show info from blueprint API. + +![example][exampleimg] + +## Installation + +1. Using you tool of choice open the directory (folder) for your HA configuration (where you find `configuration.yaml`). +2. If you do not have a `custom_components` directory (folder) there, you need to create it. +3. In the `custom_components` directory (folder) create a new folder called `blueprint`. +4. Download _all_ the files from the `custom_components/blueprint/` directory (folder) in this repository. +5. Place the files you downloaded in the new directory (folder) you created. +6. Add `blueprint:` to your HA configuration. + +Using your HA configuration directory (folder) as a starting point you should now also have this: + +```text +custom_components/blueprint/__init__.py +custom_components/blueprint/const.py +custom_components/blueprint/sensor.py +``` + +## Example configuration.yaml + +```yaml +blueprint: +``` + + +*** + +[exampleimg]: example.png +[buymecoffee]: https://www.buymeacoffee.com/ludeeus +[buymecoffeebedge]: https://camo.githubusercontent.com/cd005dca0ef55d7725912ec03a936d3a7c8de5b5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6275792532306d6525323061253230636f666665652d646f6e6174652d79656c6c6f772e737667 +[blueprint]: https://github.com/custom-components/blueprint +[customupdater]: https://github.com/custom-components/custom_updater +[customupdaterbadge]: https://img.shields.io/badge/custom__updater-true-success.svg \ No newline at end of file diff --git a/custom_components/blueprint/__init__.py b/custom_components/blueprint/__init__.py new file mode 100644 index 0000000..d2fbd04 --- /dev/null +++ b/custom_components/blueprint/__init__.py @@ -0,0 +1,66 @@ +""" +Component to integrate with https://blueprint.com/api + +For more details about this component, please refer to +https://github.com/custom-components/blueprint +""" +import os +import logging +import requests +from homeassistant.helpers import discovery + +from .const import * # pylint: disable=wildcard-import + +VERSION = '0.0.1' +_LOGGER = logging.getLogger(__name__) + + # pylint: disable=unused-argument + +async def async_setup(hass, config): + """Set up this component.""" + + # Print startup message + startup = STARTUP.format(name=DOMAIN, version=VERSION, issueurl=ISSUE_URL) + _LOGGER.info(startup) + + # Check that all required files are present + file_check = await check_files(hass) + if not file_check: + return False + + # Create DATA dict + hass.data[DOMAIN_DATA] = {} + + # Load platforms + for platform in PLATFORMS: + hass.async_create_task( + discovery.async_load_platform(hass, platform, DOMAIN, {}, config)) + return True + + +async def update_data(hass): + """Update data.""" + try: + request = requests.get(URL) + jsondata = request.json() + hass.data[DOMAIN_DATA] = jsondata + except Exception as error: # pylint: disable=broad-except + _LOGGER.error("Could not update data - %s", error) + + +async def check_files(hass): + """Retrun bool that idicate that all files are present.""" + base = "{}/custom_components/{}/".format(hass.config.path(), DOMAIN) + missing = [] + for file in REQUIRED_FILES: + fullpath = "{}{}".format(base, file) + if not os.path.exists(fullpath): + missing.append(file) + + if missing: + _LOGGER.critical("The following files are missing: %s", str(missing)) + returnvalue = False + else: + returnvalue = True + + return returnvalue diff --git a/custom_components/blueprint/const.py b/custom_components/blueprint/const.py new file mode 100644 index 0000000..fb7d3c3 --- /dev/null +++ b/custom_components/blueprint/const.py @@ -0,0 +1,18 @@ +"""Consts""" +DOMAIN = 'blueprint' +DOMAIN_DATA = '{}_data'.format(DOMAIN) +VERSION = '0.0.1' +URL = 'https://blueprint.com/api' +REQUIRED_FILES = ['sensor.py', 'const.py'] +ISSUE_URL = 'https://github.com/custom-components/blueprint/issues' +PLATFORMS = ['sensor'] + +STARTUP = """ +---------------------------------------------- +{name} +Version: {version} +This is a custom component +If you have any issues with this you need to open an issue here: +{issueurl} +---------------------------------------------- +""" diff --git a/custom_components/blueprint/sensor.py b/custom_components/blueprint/sensor.py new file mode 100644 index 0000000..197eec8 --- /dev/null +++ b/custom_components/blueprint/sensor.py @@ -0,0 +1,42 @@ +"""Sensor platform for blueprint""" +from homeassistant.helpers.entity import Entity +from . import update_data +from .const import * # pylint: disable=wildcard-import, unused-wildcard-import + +ICON = 'mdi:format-quote-close' + + +async def async_setup_platform( + hass, config, async_add_entities, discovery_info=None): # pylint: disable=unused-argument + """Setup sensor platform.""" + async_add_entities([blueprintSensor(hass)], True) + + +class blueprintSensor(Entity): + """blueprint Sensor class.""" + def __init__(self, hass): + self.hass = hass + self._state = None + + async def async_update(self): + """Update the sensor.""" + await update_data(self.hass) + updated = self.hass.data[DOMAIN_DATA].get('compliment') + if updated is None: + updated = self._state + self._state = updated.capitalize() + + @property + def name(self): + """Return the name of the sensor.""" + return DOMAIN + + @property + def state(self): + """Return the state of the sensor.""" + return self._state + + @property + def icon(self): + """Return the icon of the sensor.""" + return ICON diff --git a/image.png b/image.png new file mode 100644 index 0000000..67a3e6c Binary files /dev/null and b/image.png differ diff --git a/resorces.json b/resorces.json new file mode 100644 index 0000000..5754215 --- /dev/null +++ b/resorces.json @@ -0,0 +1,4 @@ +[ + "https://raw.githubusercontent.com/custom-components/blueprint/master/custom_components/blueprint/const.py", + "https://raw.githubusercontent.com/custom-components/blueprint/master/custom_components/blueprint/sensor.py" +] \ No newline at end of file