From ac54b72f3ec45443f486b0cc5d714c3bca226c91 Mon Sep 17 00:00:00 2001 From: ludeeus Date: Sun, 10 Nov 2019 14:30:53 +0000 Subject: [PATCH] Update stuff --- .devcontainer/Dockerfile | 17 ------- .devcontainer/README.md | 53 ---------------------- .devcontainer/custom_component_helper | 26 ----------- .devcontainer/devcontainer.json | 17 +++++-- .devcontainer/images/reopen.png | Bin 8177 -> 0 bytes .gitignore | 1 + .vscode/tasks.json | 48 ++++---------------- custom_components/authenticated/sensor.py | 31 +++++++------ 8 files changed, 37 insertions(+), 156 deletions(-) delete mode 100644 .devcontainer/Dockerfile delete mode 100644 .devcontainer/README.md delete mode 100644 .devcontainer/custom_component_helper delete mode 100644 .devcontainer/images/reopen.png create mode 100644 .gitignore 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 cbcec3c7b87925be0a0e3c6c7db5c32d03380b1b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8177 zcmc(EXH-*Lv@Rk=Y$zzGbSa@Dpi~1y`hgG-1wo3^LP>~$xNp2S#{03?-fOS1)|%g%bI5e;fY+3F& z5&Pr)btlUh)@139caOd?;qKV#0}v>gjyr?8S-H{D9iA)zVcTfw?Dqd}Lvqhh{y(Cu z9?p!~#=%EFdX-TnRh(~Ug}`i-32#@V@tud$D|EM6SwqKa?e)G%cXAGHePzcE+_CND ztnpaF3+1qWyFHjvP7)YCqPv~M8mdfLF6c4R=6W9cc&96jy=8{JR)-PuV-t39D&`VC&R04t$u={3xbn`%Wex}m$j zq(iX<7RdDmC$4qLPiwXHZzL4f>j!)KtwRCz(mrd;3g!nKu6l<1m@TFZZ)sdK!(jA`f0nXRvwJ_G3>Lq?iK`6WDv&tv>dy zrUNgwKb3P=HqE|u2wL57I`O)vvXc-jPO$U|^xH(97x`c-bq#yTic498zd^l(%TX0Z zo=lZT%j#&jOU+hc$F`|KW=((xout1@l%K1^*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$=gJ05Df;SBhmGa91!g=-bx2!=XYgsv>vp`q6>=v@C7ZbdvZ_$Te-M+ZSc&^i z5)eKyMmG1EHuww|Sra%Q^@`+4=jlhQm0tI{q;S#X!n=y6omZHa2SPe~{HFbDCxS~3 zc(*1z7G_u>sgMbZ@7TfB21uF|2DqRac<1(bki)b{HM>ki_ljv~|ArKF(${rI zlPH{SymCieII}i*t8n*;AB%-p^F%3y7T7uDW2g`pt9c4^8zF{h@9j|%3Ode^nQyAM zIe8RZ5ZhSXEKVScX65<<27Vs}-X4T~if2e%22ReWQbvNr3B?n^vmqSVWd13u+J z61N+o&3LkMdl{g|!v`sPn*l8W+Z&xdDbtRAAIyXR6G6EF+u_V89O(SC( 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