diff --git a/.github/main.workflow b/.github/main.workflow index 1fdc782..4096531 100644 --- a/.github/main.workflow +++ b/.github/main.workflow @@ -1,19 +1,10 @@ workflow "Trigger: Push to master from admin account" { on = "push" resolves = [ - "HA Index", - "push" + "HA Index" ] } -workflow "Trigger: Push" { - on = "push" - resolves = [ - "Black Code Formatter Check" - ] -} - - action "branch-filter" { uses = "actions/bin/filter@master" args = "branch master" @@ -31,26 +22,4 @@ action "HA Index" { uses = "ludeeus/actions/haindex@master" secrets = ["GITHUB_TOKEN"] needs = ["branch-filter", "Access control"] -} - -action "Black Code Formatter Fix" { - uses = "lgeiger/black-action@v1.0.1" - args = "$GITHUB_WORKSPACE" -} - -action "Black Code Formatter Check" { - uses = "lgeiger/black-action@v1.0.1" - args = "$GITHUB_WORKSPACE --check" -} - -action "push" { - uses = "ludeeus/actions/push@master" - env = { - PUSHMAIL = "ludeeus@gmail.com" - PUSHNAME = "ludeeus" - PUSHBRANCH = "master" - PUSHMESSAGE = "Action commit" - } - needs = ["Black Code Formatter Fix"] - secrets = ["GITHUB_TOKEN"] } \ No newline at end of file diff --git a/README.md b/README.md index 618f6dd..f8fc5b5 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,6 @@ custom_components/blueprint/sensor.py blueprint: ``` - *** [exampleimg]: example.png diff --git a/custom_components/blueprint/__init__.py b/custom_components/blueprint/__init__.py index 36da949..da29127 100644 --- a/custom_components/blueprint/__init__.py +++ b/custom_components/blueprint/__init__.py @@ -1,5 +1,5 @@ """ -Component to integrate with https://blueprint.com/api +Component to integrate with blueprint For more details about this component, please refer to https://github.com/custom-components/blueprint @@ -8,10 +8,10 @@ import os import logging import requests from homeassistant.helpers import discovery +from .const import ( + DOMAIN_DATA, DOMAIN, ISSUE_URL, PLATFORMS, REQUIRED_FILES, STARTUP, URL, + VERSION) -from .const import * # pylint: disable=wildcard-import - -VERSION = "0.0.1" _LOGGER = logging.getLogger(__name__) # pylint: disable=unused-argument @@ -42,6 +42,7 @@ async def async_setup(hass, config): async def update_data(hass): """Update data.""" + # This is where the main logic to update platform data goes. try: request = requests.get(URL) jsondata = request.json() @@ -52,6 +53,7 @@ async def update_data(hass): async def check_files(hass): """Retrun bool that idicate that all files are present.""" + # Verify that the user downloaded all files. base = "{}/custom_components/{}/".format(hass.config.path(), DOMAIN) missing = [] for file in REQUIRED_FILES: diff --git a/custom_components/blueprint/const.py b/custom_components/blueprint/const.py index 3ee6f46..fe7fb0d 100644 --- a/custom_components/blueprint/const.py +++ b/custom_components/blueprint/const.py @@ -1,11 +1,11 @@ -"""Consts""" +"""Conststants.""" +# Base component constants DOMAIN = "blueprint" DOMAIN_DATA = "{}_data".format(DOMAIN) VERSION = "0.0.1" -URL = "https://blueprint.com/api" +PLATFORMS = ["sensor"] REQUIRED_FILES = ["sensor.py", "const.py"] ISSUE_URL = "https://github.com/custom-components/blueprint/issues" -PLATFORMS = ["sensor"] STARTUP = """ ---------------------------------------------- @@ -16,3 +16,9 @@ If you have any issues with this you need to open an issue here: {issueurl} ---------------------------------------------- """ + +# Operational +URL = 'https://jsonplaceholder.typicode.com/todos/1' + +# Icons +SENSOR_ICON = "mdi:format-quote-close" diff --git a/custom_components/blueprint/sensor.py b/custom_components/blueprint/sensor.py index d758ff7..f27dc56 100644 --- a/custom_components/blueprint/sensor.py +++ b/custom_components/blueprint/sensor.py @@ -1,37 +1,47 @@ """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" +from .const import DOMAIN as NAME, DOMAIN_DATA, SENSOR_ICON async def async_setup_platform( - hass, config, async_add_entities, discovery_info=None + hass, config, async_add_entities, discovery_info=None ): # pylint: disable=unused-argument """Setup sensor platform.""" - async_add_entities([blueprintSensor(hass)], True) + async_add_entities([BlueprintSensor(hass)], True) -class blueprintSensor(Entity): +class BlueprintSensor(Entity): """blueprint Sensor class.""" def __init__(self, hass): self.hass = hass + self.attr = {} self._state = None async def async_update(self): """Update the sensor.""" + # Send update "signal" to the component await update_data(self.hass) - updated = self.hass.data[DOMAIN_DATA].get("compliment") - if updated is None: + + # Get new data (if any) + updated = self.hass.data[DOMAIN_DATA] + + # Check if there is data + if updated.get("title") is None: updated = self._state + + # Set/update the state, and make sure it looks good by capitalizing it self._state = updated.capitalize() + # Set/update attributes + self.attr['user_id'] = updated.get('userId') + self.attr['completed'] = updated.get('completed') + @property def name(self): """Return the name of the sensor.""" - return DOMAIN + return NAME @property def state(self): @@ -41,4 +51,9 @@ class blueprintSensor(Entity): @property def icon(self): """Return the icon of the sensor.""" - return ICON + return SENSOR_ICON + + @property + def device_state_attributes(self): + """Return the state attributes.""" + return self.attr diff --git a/example.png b/example.png new file mode 100644 index 0000000..c2d4244 Binary files /dev/null and b/example.png differ diff --git a/image.png b/image.png deleted file mode 100644 index 67a3e6c..0000000 Binary files a/image.png and /dev/null differ