diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile deleted file mode 100644 index 885a3b4..0000000 --- a/.devcontainer/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM python:3.7 - -RUN apt-get update \ - && apt-get install -y --no-install-recommends \ - git \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* - -RUN python -m pip install --upgrade colorlog black pylint -RUN python -m pip install --upgrade git+git://github.com/home-assistant/home-assistant.git@dev -RUN cd && mkdir -p /config/custom_components - - -WORKDIR /workspace - -# Set the default shell to bash instead of sh -ENV SHELL /bin/bash \ No newline at end of file diff --git a/.devcontainer/README.md b/.devcontainer/README.md deleted file mode 100644 index f52282a..0000000 --- a/.devcontainer/README.md +++ /dev/null @@ -1,53 +0,0 @@ -# Devcontainer - -_The easiest way to contribute to and/or test this repository._ - -## Requirements - -- [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) -- [docker](https://docs.docker.com/install/) -- [VS Code](https://code.visualstudio.com/) -- [Remote - Containers (VSC Extention)](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) - -[More info about requirements and devcontainer in general](https://code.visualstudio.com/docs/remote/containers#_getting-started) - -## How to use Devcontainer for development/test - -1. Make sure your computer meets the requirements. -1. Fork this repository. -1. Clone the repository to your computer. -1. Open the repository using VS Code. - -When you open this repository with VSCode and your computer meets the requirements you are asked to "Reopen in Container", do that. - -![reopen](images/reopen.png) - -If you don't see this notification, open the command pallet (ctrl+shift+p) and select `Remote-Containers: Reopen Folder in Container`. - -_It will now build the devcontainer._ - -The container have some "tasks" to help you testing your changes. - -## Custom Tasks in this repository - -_Start "tasks" by opening the the command pallet (ctrl+shift+p) and select `Tasks: Run Task`_ - -Running tasks like `Start Home Assistant on port 8124` can be restarted by opening the the command pallet (ctrl+shift+p) and select `Tasks: Restart Running Task`, then select the task you want to restart. - -### Start Home Assistant on port 8124 - -This will copy the configuration and the integration files to the expected location in the container. - -And start up Home Assistant on [port 8124.](http://localhost:8124) - -### Upgrade Home Assistant to latest dev - -This will upgrade Home Assistant to the latest dev version. - -### Set Home Assistant Version - -This allows you to specify a version of Home Assistant to install inside the devcontainer. - -### Home Assistant Config Check - -This runs a config check to make sure your config is valid. diff --git a/.devcontainer/custom_component_helper b/.devcontainer/custom_component_helper deleted file mode 100644 index 40165d9..0000000 --- a/.devcontainer/custom_component_helper +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -function StartHomeAssistant { - echo "Copy configuration.yaml" - cp -f .devcontainer/configuration.yaml /config || echo ".devcontainer/configuration.yaml are missing!" exit 1 - - echo "Copy the custom component" - rm -R /config/custom_components/ || echo "" - cp -r custom_components /config/custom_components/ || echo "Could not copy the custom_component" exit 1 - - echo "Start Home Assistant" - hass -c /config -} - -function UpdgradeHomeAssistantDev { - python -m pip install --upgrade git+git://github.com/home-assistant/home-assistant.git@dev -} - -function SetHomeAssistantVersion { - read -p 'Version: ' version - python -m pip install --upgrade homeassistant==$version -} - -function HomeAssistantConfigCheck { - hass -c /config --script check_config -} \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 795ced9..a27493a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,11 +1,15 @@ // See https://aka.ms/vscode-remote/devcontainer.json for format details. { + "name": "Custom integration authenticated", + "image": "ludeeus/devcontainer:integration", "context": "..", - "dockerFile": "Dockerfile", - "appPort": "8124:8123", + "appPort": [ + "9123:8123" + ], + "postCreateCommand": "dc install", "runArgs": [ - "-e", - "GIT_EDTIOR='code --wait'" + "-v", + "${env:HOME}${env:USERPROFILE}/.ssh:/tmp/.ssh" // This is added so you can push from inside the container ], "extensions": [ "ms-python.python", @@ -13,7 +17,10 @@ "tabnine.tabnine-vscode" ], "settings": { - "python.pythonPath": "/usr/local/bin/python", + "files.eol": "\n", + "editor.tabSize": 4, + "terminal.integrated.shell.linux": "/bin/bash", + "python.pythonPath": "/usr/bin/python3", "python.linting.pylintEnabled": true, "python.linting.enabled": true, "python.formatting.provider": "black", diff --git a/.devcontainer/images/reopen.png b/.devcontainer/images/reopen.png deleted file mode 100644 index cbcec3c..0000000 Binary files a/.devcontainer/images/reopen.png and /dev/null differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7e99e36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 31504d9..723b57d 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -2,59 +2,27 @@ "version": "2.0.0", "tasks": [ { - "label": "Start Home Assistant on port 8124", + "label": "Run Home Assistant on port 9123", "type": "shell", - "command": "source .devcontainer/custom_component_helper && StartHomeAssistant", - "group": { - "kind": "test", - "isDefault": true, - }, - "presentation": { - "reveal": "always", - "panel": "new" - }, + "command": "dc start", "problemMatcher": [] }, { - "label": "Upgrade Home Assistant to latest dev", + "label": "Run Home Assistant configuration against /config", "type": "shell", - "command": "source .devcontainer/custom_component_helper && UpdgradeHomeAssistantDev", - "group": { - "kind": "test", - "isDefault": true, - }, - "presentation": { - "reveal": "always", - "panel": "new" - }, + "command": "dc check", "problemMatcher": [] }, { - "label": "Set Home Assistant Version", + "label": "Upgrade Home Assistant to latest dev", "type": "shell", - "command": "source .devcontainer/custom_component_helper && SetHomeAssistantVersion", - "group": { - "kind": "test", - "isDefault": true, - }, - "presentation": { - "reveal": "always", - "panel": "new" - }, + "command": "dc start", "problemMatcher": [] }, { - "label": "Home Assistant Config Check", + "label": "Install a spesific version of Home Assistant", "type": "shell", - "command": "source .devcontainer/custom_component_helper && HomeAssistantConfigCheck", - "group": { - "kind": "test", - "isDefault": true, - }, - "presentation": { - "reveal": "always", - "panel": "new" - }, + "command": "dc set-version", "problemMatcher": [] } ] diff --git a/custom_components/authenticated/sensor.py b/custom_components/authenticated/sensor.py index 7da47ea..ec35299 100644 --- a/custom_components/authenticated/sensor.py +++ b/custom_components/authenticated/sensor.py @@ -182,6 +182,8 @@ def update(self): if new == stored: continue + if new is None or stored is None: + continue elif new > stored: updated = True _LOGGER.info("New successfull login from known IP (%s)", access) @@ -322,25 +324,24 @@ def load_authentications(authfile, exclude): if ValidateIP(token["last_used_ip"]) in ip_network( excludeaddress, False ): - break - else: - if token["last_used_ip"] in tokens_cleaned: - if ( - token["last_used_at"] - > tokens_cleaned[token["last_used_ip"]]["last_used_at"] - ): - tokens_cleaned[token["last_used_ip"]]["last_used_at"] = token[ - "last_used_at" - ] - tokens_cleaned[token["last_used_ip"]]["user_id"] = token[ - "user_id" - ] - else: - tokens_cleaned[token["last_used_ip"]] = {} + continue + if token.get("last_used_at") is None: + continue + if token["last_used_ip"] in tokens_cleaned: + if ( + token["last_used_at"] + > tokens_cleaned[token["last_used_ip"]]["last_used_at"] + ): tokens_cleaned[token["last_used_ip"]]["last_used_at"] = token[ "last_used_at" ] tokens_cleaned[token["last_used_ip"]]["user_id"] = token["user_id"] + else: + tokens_cleaned[token["last_used_ip"]] = {} + tokens_cleaned[token["last_used_ip"]]["last_used_at"] = token[ + "last_used_at" + ] + tokens_cleaned[token["last_used_ip"]]["user_id"] = token["user_id"] except Exception: # Gotta Catch 'Em All pass