diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index b51ce99f..c4100ae0 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,9 +1,7 @@ { "name": "Tesla Custom Component development", "image": "ghcr.io/ludeeus/devcontainer/integration:stable", - "appPort": [ - "9123:8123" - ], + "appPort": ["9123:8123"], "postCreateCommand": "bash .devcontainer/post-create.sh", "extensions": [ "ms-python.python", @@ -30,4 +28,4 @@ "editor.formatOnType": true, "files.trimTrailingWhitespace": true } -} \ No newline at end of file +} diff --git a/.github/workflows/lintpr.yml b/.github/workflows/lintpr.yml index 26200b28..ad6df65f 100644 --- a/.github/workflows/lintpr.yml +++ b/.github/workflows/lintpr.yml @@ -14,4 +14,4 @@ jobs: steps: - uses: amannn/action-semantic-pull-request@v4 env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a0aeff7a..5e99e089 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,6 +22,11 @@ repos: - id: debug-statements - id: check-toml - id: check-json + exclude: > + (?x)^( + .vscode/settings.json| + .vscode/launch.json + )$ # This one is slow and doesn't check for much # - detect-private-key # This is very slow, so I recommend disabling it. @@ -30,14 +35,14 @@ repos: - id: check-yaml exclude: ^recipes/.* repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + rev: v4.4.0 # --- Commit msg checks --- - hooks: - id: commitizen stages: ["commit-msg"] repo: https://github.com/commitizen-tools/commitizen - rev: v2.28.0 + rev: v2.38.0 # --- Linters --- - hooks: - id: dockerfile_lint @@ -46,18 +51,18 @@ repos: - hooks: - id: black repo: https://github.com/psf/black - rev: 22.6.0 + rev: 23.1a1 - repo: https://github.com/pre-commit/mirrors-prettier hooks: - id: prettier - rev: v2.7.1 + rev: v3.0.0-alpha.4 - repo: https://github.com/asottile/pyupgrade - rev: v2.35.0 + rev: v3.3.1 hooks: - id: pyupgrade args: [--py38-plus] - repo: https://github.com/PyCQA/prospector - rev: 1.7.7 + rev: v1.8.3 hooks: - id: prospector exclude: ^(tests)/.+\.py$ @@ -71,14 +76,31 @@ repos: - --configfile=tests/bandit.yaml files: ^(tests)/.+\.py$ - repo: https://github.com/PyCQA/isort - rev: 5.10.1 + rev: 5.11.4 hooks: - id: isort -# - repo: local -# hooks: -# - id: pytest-check -# name: pytest-check -# entry: pytest -# language: system -# pass_filenames: false -# always_run: true + # - repo: local + # hooks: + # - id: pytest-check + # name: pytest-check + # entry: pytest + # language: system + # pass_filenames: false + # always_run: true + - repo: https://github.com/floatingpurr/sync_with_poetry + rev: "0.4.0" # the revision or tag to clone at + hooks: + - id: sync_with_poetry + args: [] # optional args + +ci: + autofix_commit_msg: | + style: auto fixes from pre-commit.com hooks + + for more information, see https://pre-commit.ci + autofix_prs: true + autoupdate_branch: "" + autoupdate_commit_msg: "build: pre-commit autoupdate" + autoupdate_schedule: weekly + skip: [] + submodules: false diff --git a/.vscode/launch.json b/.vscode/launch.json index 240488f7..b92c595d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,35 +1,35 @@ { - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + // Example of attaching to local debug server + "name": "Python: Attach Local", + "type": "python", + "request": "attach", + "port": 5678, + "justMyCode": false, + "host": "localhost", + "pathMappings": [ { - // Example of attaching to local debug server - "name": "Python: Attach Local", - "type": "python", - "request": "attach", - "port": 5678, - "justMyCode": false, - "host": "localhost", - "pathMappings": [ - { - "localRoot": "${workspaceFolder}", - "remoteRoot": "." - } - ] - }, + "localRoot": "${workspaceFolder}", + "remoteRoot": "." + } + ] + }, + { + // Example of attaching to my production server + "name": "Python: Attach Remote", + "type": "python", + "request": "attach", + "port": 5678, + "host": "homeassistant.local", + "pathMappings": [ { - // Example of attaching to my production server - "name": "Python: Attach Remote", - "type": "python", - "request": "attach", - "port": 5678, - "host": "homeassistant.local", - "pathMappings": [ - { - "localRoot": "${workspaceFolder}", - "remoteRoot": "/usr/src/homeassistant" - } - ] + "localRoot": "${workspaceFolder}", + "remoteRoot": "/usr/src/homeassistant" } - ] -} \ No newline at end of file + ] + } + ] +} diff --git a/.vscode/settings.default.json b/.vscode/settings.default.json index 386af462..d7ebf65a 100644 --- a/.vscode/settings.default.json +++ b/.vscode/settings.default.json @@ -1,10 +1,8 @@ { - "python.testing.pytestArgs": [ - "tests" - ], - "python.testing.unittestEnabled": false, - "python.testing.pytestEnabled": true, - "files.associations": { - "*.yaml": "home-assistant" - } -} \ No newline at end of file + "python.testing.pytestArgs": ["tests"], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true, + "files.associations": { + "*.yaml": "home-assistant" + } +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json index a4ae2df5..d61c158e 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,35 +1,35 @@ { - "version": "2.0.0", - "tasks": [ - { - "label": "Run Home Assistant on port 9123", - "type": "shell", - "command": "container start", - "problemMatcher": [] - }, - { - "label": "Run Home Assistant configuration against /config", - "type": "shell", - "command": "container check", - "problemMatcher": [] - }, - { - "label": "Upgrade Home Assistant to latest dev", - "type": "shell", - "command": "container install", - "problemMatcher": [] - }, - { - "label": "Install a specific version of Home Assistant", - "type": "shell", - "command": "container set-version", - "problemMatcher": [] - }, - { - "label": "Serve Documentation on port 8000", - "type": "shell", - "command": "mkdocs -v serve", - "problemMatcher": [] - } - ] -} \ No newline at end of file + "version": "2.0.0", + "tasks": [ + { + "label": "Run Home Assistant on port 9123", + "type": "shell", + "command": "container start", + "problemMatcher": [] + }, + { + "label": "Run Home Assistant configuration against /config", + "type": "shell", + "command": "container check", + "problemMatcher": [] + }, + { + "label": "Upgrade Home Assistant to latest dev", + "type": "shell", + "command": "container install", + "problemMatcher": [] + }, + { + "label": "Install a specific version of Home Assistant", + "type": "shell", + "command": "container set-version", + "problemMatcher": [] + }, + { + "label": "Serve Documentation on port 8000", + "type": "shell", + "command": "mkdocs -v serve", + "problemMatcher": [] + } + ] +} diff --git a/CHANGELOG.md b/CHANGELOG.md index 101a8ab1..a3120b2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,171 +3,239 @@ ## v3.9.0 (2022-12-29) + ### Feature -* Add emission test button ([#454](https://github.com/alandtse/tesla/issues/454)) ([`8d40beb`](https://github.com/alandtse/tesla/commit/8d40beb45790e06146991488934c24e1c3f4322d)) -* Add scheduled departure and charge timestamp attributes ([#458](https://github.com/alandtse/tesla/issues/458)) ([`b979846`](https://github.com/alandtse/tesla/commit/b97984605f467776b1caa871f72f9534fd4496a8)) -* Add dynamic debug logging ([#448](https://github.com/alandtse/tesla/issues/448)) ([`d310ae5`](https://github.com/alandtse/tesla/commit/d310ae506afafd4a16e9a0bb07405b929625ebda)) + +- Add emission test button ([#454](https://github.com/alandtse/tesla/issues/454)) ([`8d40beb`](https://github.com/alandtse/tesla/commit/8d40beb45790e06146991488934c24e1c3f4322d)) +- Add scheduled departure and charge timestamp attributes ([#458](https://github.com/alandtse/tesla/issues/458)) ([`b979846`](https://github.com/alandtse/tesla/commit/b97984605f467776b1caa871f72f9534fd4496a8)) +- Add dynamic debug logging ([#448](https://github.com/alandtse/tesla/issues/448)) ([`d310ae5`](https://github.com/alandtse/tesla/commit/d310ae506afafd4a16e9a0bb07405b929625ebda)) ### Fix -* Make destination location unknown after arrival ([#460](https://github.com/alandtse/tesla/issues/460)) ([`5781cea`](https://github.com/alandtse/tesla/commit/5781cea8515e451a4a2c8dbf0aa7e973094a7feb)) -* Account for time passing between updates ([#419](https://github.com/alandtse/tesla/issues/419)) ([`02751a2`](https://github.com/alandtse/tesla/commit/02751a203a1d0dcfb6efd570cfb5246773f03e16)) -* Replace deprecated is_metric ([#343](https://github.com/alandtse/tesla/issues/343)) ([`87005fc`](https://github.com/alandtse/tesla/commit/87005fc353102d46fcd95a20a173a007d6d41b00)) + +- Make destination location unknown after arrival ([#460](https://github.com/alandtse/tesla/issues/460)) ([`5781cea`](https://github.com/alandtse/tesla/commit/5781cea8515e451a4a2c8dbf0aa7e973094a7feb)) +- Account for time passing between updates ([#419](https://github.com/alandtse/tesla/issues/419)) ([`02751a2`](https://github.com/alandtse/tesla/commit/02751a203a1d0dcfb6efd570cfb5246773f03e16)) +- Replace deprecated is_metric ([#343](https://github.com/alandtse/tesla/issues/343)) ([`87005fc`](https://github.com/alandtse/tesla/commit/87005fc353102d46fcd95a20a173a007d6d41b00)) ## v3.8.1 (2022-12-21) + ### Fix -* Handle battery range attributes NoneType ([#453](https://github.com/alandtse/tesla/issues/453)) ([`90f7d0d`](https://github.com/alandtse/tesla/commit/90f7d0ddb9140dae92c446dd7274a7e27abd4f3d)) + +- Handle battery range attributes NoneType ([#453](https://github.com/alandtse/tesla/issues/453)) ([`90f7d0d`](https://github.com/alandtse/tesla/commit/90f7d0ddb9140dae92c446dd7274a7e27abd4f3d)) ## v3.8.0 (2022-12-21) + ### Feature -* Add user present and User ID ([#446](https://github.com/alandtse/tesla/issues/446)) ([`865c637`](https://github.com/alandtse/tesla/commit/865c6377649f1c0bf94f39d98a59e4e5d0891e31)) -* Add estimated battery range attributes ([#443](https://github.com/alandtse/tesla/issues/443)) ([`7584fdc`](https://github.com/alandtse/tesla/commit/7584fdcdc64d1c752dc34bdafd08c47ded6526df)) -* Add scheduled departure and charging ([#441](https://github.com/alandtse/tesla/issues/441)) ([`f555131`](https://github.com/alandtse/tesla/commit/f55513162e5cd03633156fa59073759ef7d7052b)) + +- Add user present and User ID ([#446](https://github.com/alandtse/tesla/issues/446)) ([`865c637`](https://github.com/alandtse/tesla/commit/865c6377649f1c0bf94f39d98a59e4e5d0891e31)) +- Add estimated battery range attributes ([#443](https://github.com/alandtse/tesla/issues/443)) ([`7584fdc`](https://github.com/alandtse/tesla/commit/7584fdcdc64d1c752dc34bdafd08c47ded6526df)) +- Add scheduled departure and charging ([#441](https://github.com/alandtse/tesla/issues/441)) ([`f555131`](https://github.com/alandtse/tesla/commit/f55513162e5cd03633156fa59073759ef7d7052b)) ### Fix -* Remove state class from timestamp sensors ([#440](https://github.com/alandtse/tesla/issues/440)) ([`43f7169`](https://github.com/alandtse/tesla/commit/43f7169b6aa43c5fe08865e75b8172cbe231d5df)) + +- Remove state class from timestamp sensors ([#440](https://github.com/alandtse/tesla/issues/440)) ([`43f7169`](https://github.com/alandtse/tesla/commit/43f7169b6aa43c5fe08865e75b8172cbe231d5df)) ## v3.7.1 (2022-12-18) + ### Fix -* Fix seat map for auto climate command ([#435](https://github.com/alandtse/tesla/issues/435)) ([`c96e5b0`](https://github.com/alandtse/tesla/commit/c96e5b0ac2794f7569846af5cf78f6f8f6545e3d)) + +- Fix seat map for auto climate command ([#435](https://github.com/alandtse/tesla/issues/435)) ([`c96e5b0`](https://github.com/alandtse/tesla/commit/c96e5b0ac2794f7569846af5cf78f6f8f6545e3d)) ### Documentation -* Update readme with new features ([`8a518c9`](https://github.com/alandtse/tesla/commit/8a518c93b05f31f2a0c9817d624a4b13dac944fc)) + +- Update readme with new features ([`8a518c9`](https://github.com/alandtse/tesla/commit/8a518c93b05f31f2a0c9817d624a4b13dac944fc)) ## v3.7.0 (2022-12-11) + ### Feature -* Add destination location entities ([#423](https://github.com/alandtse/tesla/issues/423)) ([`a4ec318`](https://github.com/alandtse/tesla/commit/a4ec318eb44838c6a6ad0164369e98aa563aff32)) + +- Add destination location entities ([#423](https://github.com/alandtse/tesla/issues/423)) ([`a4ec318`](https://github.com/alandtse/tesla/commit/a4ec318eb44838c6a6ad0164369e98aa563aff32)) ## v3.6.1 (2022-12-11) + ### Fix -* Use old pressure consts for ha < 2022.11 ([#418](https://github.com/alandtse/tesla/issues/418)) ([`ad9c41c`](https://github.com/alandtse/tesla/commit/ad9c41c71ea93db9294ff4203b61f1e6f6a4b697)) + +- Use old pressure consts for ha < 2022.11 ([#418](https://github.com/alandtse/tesla/issues/418)) ([`ad9c41c`](https://github.com/alandtse/tesla/commit/ad9c41c71ea93db9294ff4203b61f1e6f6a4b697)) ## v3.6.0 (2022-12-09) + ### Feature -* Add Auto seat heater option ([#404](https://github.com/alandtse/tesla/issues/404)) ([`7e02a42`](https://github.com/alandtse/tesla/commit/7e02a423cf59c8d70c58cc623da59389044da8b4)) -* Add valet mode switch ([#405](https://github.com/alandtse/tesla/issues/405)) ([`01116d1`](https://github.com/alandtse/tesla/commit/01116d1ff5b5ea66bba6d73ad4089a2c38f03ffe)) + +- Add Auto seat heater option ([#404](https://github.com/alandtse/tesla/issues/404)) ([`7e02a42`](https://github.com/alandtse/tesla/commit/7e02a423cf59c8d70c58cc623da59389044da8b4)) +- Add valet mode switch ([#405](https://github.com/alandtse/tesla/issues/405)) ([`01116d1`](https://github.com/alandtse/tesla/commit/01116d1ff5b5ea66bba6d73ad4089a2c38f03ffe)) ### Fix -* Always show charge energy for current and last session ([#414](https://github.com/alandtse/tesla/issues/414)) ([`be6c1f0`](https://github.com/alandtse/tesla/commit/be6c1f09e51cb4954a67573bed04ea4151a488b0)) -* Fix arrows for window cover ([#407](https://github.com/alandtse/tesla/issues/407)) ([`108567c`](https://github.com/alandtse/tesla/commit/108567cb1b53824665ebf2ae890efd1c4f0812e5)) -* Turn climate on when turning seat heater on ([#406](https://github.com/alandtse/tesla/issues/406)) ([`78e90e4`](https://github.com/alandtse/tesla/commit/78e90e47f12a6f7288fe2d3b55e56984c2560628)) + +- Always show charge energy for current and last session ([#414](https://github.com/alandtse/tesla/issues/414)) ([`be6c1f0`](https://github.com/alandtse/tesla/commit/be6c1f09e51cb4954a67573bed04ea4151a488b0)) +- Fix arrows for window cover ([#407](https://github.com/alandtse/tesla/issues/407)) ([`108567c`](https://github.com/alandtse/tesla/commit/108567cb1b53824665ebf2ae890efd1c4f0812e5)) +- Turn climate on when turning seat heater on ([#406](https://github.com/alandtse/tesla/issues/406)) ([`78e90e4`](https://github.com/alandtse/tesla/commit/78e90e47f12a6f7288fe2d3b55e56984c2560628)) ## v3.5.2 (2022-12-03) + ### Fix -* Don't round when tpms is unavailable ([#398](https://github.com/alandtse/tesla/issues/398)) ([`f5a3b0d`](https://github.com/alandtse/tesla/commit/f5a3b0d23071893d913895659efe3a4ced00bf79)) + +- Don't round when tpms is unavailable ([#398](https://github.com/alandtse/tesla/issues/398)) ([`f5a3b0d`](https://github.com/alandtse/tesla/commit/f5a3b0d23071893d913895659efe3a4ced00bf79)) ## v3.5.1 (2022-12-03) + ### Fix -* Set default pressure to PSI ([#391](https://github.com/alandtse/tesla/issues/391)) ([`e4adef7`](https://github.com/alandtse/tesla/commit/e4adef75dbfef9e03b5f8b73b0621181acf3fab1)) + +- Set default pressure to PSI ([#391](https://github.com/alandtse/tesla/issues/391)) ([`e4adef7`](https://github.com/alandtse/tesla/commit/e4adef75dbfef9e03b5f8b73b0621181acf3fab1)) ## v3.5.0 (2022-12-01) + ### Feature -* Add remote start button ([#385](https://github.com/alandtse/tesla/issues/385)) ([`42b7117`](https://github.com/alandtse/tesla/commit/42b7117fe16209ccf23070b22b58e576cd2709a8)) + +- Add remote start button ([#385](https://github.com/alandtse/tesla/issues/385)) ([`42b7117`](https://github.com/alandtse/tesla/commit/42b7117fe16209ccf23070b22b58e576cd2709a8)) ## v3.4.0 (2022-11-30) + ### Feature -* Add tpms pressure sensors ([#376](https://github.com/alandtse/tesla/issues/376)) ([`b2cbe95`](https://github.com/alandtse/tesla/commit/b2cbe9575ab6e2c4a780ec15f9ebc57f45235fa5)) -* Add doors binary sensor ([#377](https://github.com/alandtse/tesla/issues/377)) ([`8b77e3c`](https://github.com/alandtse/tesla/commit/8b77e3c7b1aff6aa6761d8f86592b891099137d4)) + +- Add tpms pressure sensors ([#376](https://github.com/alandtse/tesla/issues/376)) ([`b2cbe95`](https://github.com/alandtse/tesla/commit/b2cbe9575ab6e2c4a780ec15f9ebc57f45235fa5)) +- Add doors binary sensor ([#377](https://github.com/alandtse/tesla/issues/377)) ([`8b77e3c`](https://github.com/alandtse/tesla/commit/8b77e3c7b1aff6aa6761d8f86592b891099137d4)) ## v3.3.2 (2022-11-29) + ### Fix -* Use utc time zone for charge complete sensor ([`f13c618`](https://github.com/alandtse/tesla/commit/f13c618efe2071945eb5846fc0ff3c3b645da0f8)) + +- Use utc time zone for charge complete sensor ([`f13c618`](https://github.com/alandtse/tesla/commit/f13c618efe2071945eb5846fc0ff3c3b645da0f8)) ## v3.3.1 (2022-11-27) + ### Fix -* Change timestamp calculation ([`5f92774`](https://github.com/alandtse/tesla/commit/5f9277425df93fa9ece48e2d2d27eedd433c9abb)) + +- Change timestamp calculation ([`5f92774`](https://github.com/alandtse/tesla/commit/5f9277425df93fa9ece48e2d2d27eedd433c9abb)) ## v3.3.0 (2022-11-27) + ### Feature -* Add time to full charge sensor ([#349](https://github.com/alandtse/tesla/issues/349)) ([`fbcf5fe`](https://github.com/alandtse/tesla/commit/fbcf5fe9b8345a13f9fed94dc65e9f2c93a62601)) -* Show software update statuses in version info ([#370](https://github.com/alandtse/tesla/issues/370)) ([`fac9dd1`](https://github.com/alandtse/tesla/commit/fac9dd12c1baa6e3676fb30face39514200d1606)) + +- Add time to full charge sensor ([#349](https://github.com/alandtse/tesla/issues/349)) ([`fbcf5fe`](https://github.com/alandtse/tesla/commit/fbcf5fe9b8345a13f9fed94dc65e9f2c93a62601)) +- Show software update statuses in version info ([#370](https://github.com/alandtse/tesla/issues/370)) ([`fac9dd1`](https://github.com/alandtse/tesla/commit/fac9dd12c1baa6e3676fb30face39514200d1606)) ### Fix -* Handle unresponsive cars/systems during setup ([`4d1270b`](https://github.com/alandtse/tesla/commit/4d1270b426cef4a00b8e84644aafdaa3a47407ca)) + +- Handle unresponsive cars/systems during setup ([`4d1270b`](https://github.com/alandtse/tesla/commit/4d1270b426cef4a00b8e84644aafdaa3a47407ca)) ## v3.2.0 (2022-11-21) + ### Feature -* Add binary_sensor._asleep ([#361](https://github.com/alandtse/tesla/issues/361)) ([`43deefb`](https://github.com/alandtse/tesla/commit/43deefb9a0b306c0d867413bfbc6ecb67b15fd50)) + +- Add binary_sensor.\_asleep ([#361](https://github.com/alandtse/tesla/issues/361)) ([`43deefb`](https://github.com/alandtse/tesla/commit/43deefb9a0b306c0d867413bfbc6ecb67b15fd50)) ### Fix -* Persist entities when reloaded while car is asleep ([#365](https://github.com/alandtse/tesla/issues/365)) ([`f0fc6e4`](https://github.com/alandtse/tesla/commit/f0fc6e49895547a3861a3592dcde7269b05b9305)) -* Fix usable_battery_level to match app ([#362](https://github.com/alandtse/tesla/issues/362)) ([`c9e4abb`](https://github.com/alandtse/tesla/commit/c9e4abbacba8df7571943f3008eaa1df410c9b28)) -* Update car-asleep binary sensor icon ([#364](https://github.com/alandtse/tesla/issues/364)) ([`30f319c`](https://github.com/alandtse/tesla/commit/30f319c893012c154faea0d5d6c3ef88efdb7ccd)) + +- Persist entities when reloaded while car is asleep ([#365](https://github.com/alandtse/tesla/issues/365)) ([`f0fc6e4`](https://github.com/alandtse/tesla/commit/f0fc6e49895547a3861a3592dcde7269b05b9305)) +- Fix usable_battery_level to match app ([#362](https://github.com/alandtse/tesla/issues/362)) ([`c9e4abb`](https://github.com/alandtse/tesla/commit/c9e4abbacba8df7571943f3008eaa1df410c9b28)) +- Update car-asleep binary sensor icon ([#364](https://github.com/alandtse/tesla/issues/364)) ([`30f319c`](https://github.com/alandtse/tesla/commit/30f319c893012c154faea0d5d6c3ef88efdb7ccd)) ## v3.1.0 (2022-11-14) + ### Feature -* Add window cover ([#318](https://github.com/alandtse/tesla/issues/318)) ([`bea6824`](https://github.com/alandtse/tesla/commit/bea68240d68e727e5cda803fe9df2b711ba0c6ff)) -* Add charge port latch lock ([`df7d06e`](https://github.com/alandtse/tesla/commit/df7d06ead2f7ddb499e9e254f645bd969886a86a)) + +- Add window cover ([#318](https://github.com/alandtse/tesla/issues/318)) ([`bea6824`](https://github.com/alandtse/tesla/commit/bea68240d68e727e5cda803fe9df2b711ba0c6ff)) +- Add charge port latch lock ([`df7d06e`](https://github.com/alandtse/tesla/commit/df7d06ead2f7ddb499e9e254f645bd969886a86a)) ### Fix -* Fix typo telsafi.com -> teslafi.com ([#314](https://github.com/alandtse/tesla/issues/314)) ([`9c1514a`](https://github.com/alandtse/tesla/commit/9c1514a051a1f953ab91cd1463e03da350680eda)) + +- Fix typo telsafi.com -> teslafi.com ([#314](https://github.com/alandtse/tesla/issues/314)) ([`9c1514a`](https://github.com/alandtse/tesla/commit/9c1514a051a1f953ab91cd1463e03da350680eda)) ## v3.0.2 (2022-10-27) + ### Fix -* Add missing close_cover for frunks ([`3257775`](https://github.com/alandtse/tesla/commit/325777598d13b0e2ac3b817fb4996ab60e019b2f)) + +- Add missing close_cover for frunks ([`3257775`](https://github.com/alandtse/tesla/commit/325777598d13b0e2ac3b817fb4996ab60e019b2f)) ## v3.0.1 (2022-10-24) + ### Fix -* Add open feature for frunk ([`769858f`](https://github.com/alandtse/tesla/commit/769858f442a65ee0a5bd95ae7b6d797b02fc8088)) -* Set sensor device class ([#292](https://github.com/alandtse/tesla/issues/292)) ([`658295f`](https://github.com/alandtse/tesla/commit/658295f785ae5348d73b1dc18f37ad14a1990f70)) -* Use GPS coords from Tesla API ([#289](https://github.com/alandtse/tesla/issues/289)) ([`1bc6d7f`](https://github.com/alandtse/tesla/commit/1bc6d7fd64977844102e70a3a62fd553745a15ce)) -* Use car distance units & fix solar type ([`2617d71`](https://github.com/alandtse/tesla/commit/2617d71bbc8ff1bee247c599e11077617bf6eba5)) + +- Add open feature for frunk ([`769858f`](https://github.com/alandtse/tesla/commit/769858f442a65ee0a5bd95ae7b6d797b02fc8088)) +- Set sensor device class ([#292](https://github.com/alandtse/tesla/issues/292)) ([`658295f`](https://github.com/alandtse/tesla/commit/658295f785ae5348d73b1dc18f37ad14a1990f70)) +- Use GPS coords from Tesla API ([#289](https://github.com/alandtse/tesla/issues/289)) ([`1bc6d7f`](https://github.com/alandtse/tesla/commit/1bc6d7fd64977844102e70a3a62fd553745a15ce)) +- Use car distance units & fix solar type ([`2617d71`](https://github.com/alandtse/tesla/commit/2617d71bbc8ff1bee247c599e11077617bf6eba5)) ## v3.0.0 (2022-10-22) + ### Feature -* Rewrite to add support for energy sites ([#250](https://github.com/alandtse/tesla/issues/250)) ([`6a1f9c3`](https://github.com/alandtse/tesla/commit/6a1f9c3cb663ed5543a2e778bdbaf750699b1438)) + +- Rewrite to add support for energy sites ([#250](https://github.com/alandtse/tesla/issues/250)) ([`6a1f9c3`](https://github.com/alandtse/tesla/commit/6a1f9c3cb663ed5543a2e778bdbaf750699b1438)) ### Breaking -* This is a rewrite. Multiple entitiy_ids were changed. It is recommended you remove and reinstall. Changed trunk, frunk and charger door from lock to cover entities. Created separate sensor (`TeslaCarChargerPower` class) for charger power. Moved charger amps, charger volts and charger phases extra state attributes to the new charger power sensor. Moved added range extra state attributes to the charger energy added sensor. ([`6a1f9c3`](https://github.com/alandtse/tesla/commit/6a1f9c3cb663ed5543a2e778bdbaf750699b1438)) + +- This is a rewrite. Multiple entitiy_ids were changed. It is recommended you remove and reinstall. Changed trunk, frunk and charger door from lock to cover entities. Created separate sensor (`TeslaCarChargerPower` class) for charger power. Moved charger amps, charger volts and charger phases extra state attributes to the new charger power sensor. Moved added range extra state attributes to the charger energy added sensor. ([`6a1f9c3`](https://github.com/alandtse/tesla/commit/6a1f9c3cb663ed5543a2e778bdbaf750699b1438)) ### Documentation -* Remove duplicate info from README ([#278](https://github.com/alandtse/tesla/issues/278)) ([`616d3a5`](https://github.com/alandtse/tesla/commit/616d3a5761432a06589bbad3f9bbe886f3621384)) + +- Remove duplicate info from README ([#278](https://github.com/alandtse/tesla/issues/278)) ([`616d3a5`](https://github.com/alandtse/tesla/commit/616d3a5761432a06589bbad3f9bbe886f3621384)) ## v2.4.4 (2022-10-10) + ### Fix -* Fix keyerror `charge_to_max_range` ([`0aa02c1`](https://github.com/alandtse/tesla/commit/0aa02c141680400b6ac10d43f8c99a474e379008)) + +- Fix keyerror `charge_to_max_range` ([`0aa02c1`](https://github.com/alandtse/tesla/commit/0aa02c141680400b6ac10d43f8c99a474e379008)) ### Documentation -* Update Danish Translation ([#269](https://github.com/alandtse/tesla/issues/269)) ([`73829e3`](https://github.com/alandtse/tesla/commit/73829e37c1e1a21715a069f6fed512b927d4a446)) + +- Update Danish Translation ([#269](https://github.com/alandtse/tesla/issues/269)) ([`73829e3`](https://github.com/alandtse/tesla/commit/73829e37c1e1a21715a069f6fed512b927d4a446)) ## v2.4.3 (2022-09-11) + ### Fix -* Fix Chinese location offset ([#263](https://github.com/alandtse/tesla/issues/263)) ([`3feba57`](https://github.com/alandtse/tesla/commit/3feba57298de38a8fc3601e8d3080b97344f0a91)) + +- Fix Chinese location offset ([#263](https://github.com/alandtse/tesla/issues/263)) ([`3feba57`](https://github.com/alandtse/tesla/commit/3feba57298de38a8fc3601e8d3080b97344f0a91)) ## v2.4.2 (2022-08-29) + ### Fix -* Fix grid status issue ([#258](https://github.com/alandtse/tesla/issues/258)) ([`f889173`](https://github.com/alandtse/tesla/commit/f88917321369d0faaf280e1139967eebf6df8be5)) + +- Fix grid status issue ([#258](https://github.com/alandtse/tesla/issues/258)) ([`f889173`](https://github.com/alandtse/tesla/commit/f88917321369d0faaf280e1139967eebf6df8be5)) ## v2.4.1 (2022-08-27) + ### Fix -* Bump teslajsonpy to fix solar naming ([#249](https://github.com/alandtse/tesla/issues/249)) ([`26658bd`](https://github.com/alandtse/tesla/commit/26658bd46d56d4c94cc5b99cfbcfa56a1671ee36)) + +- Bump teslajsonpy to fix solar naming ([#249](https://github.com/alandtse/tesla/issues/249)) ([`26658bd`](https://github.com/alandtse/tesla/commit/26658bd46d56d4c94cc5b99cfbcfa56a1671ee36)) ## v2.4.0 (2022-08-13) + ### Feature -* Add solar power, grid power, load power sensors ([`57d6095`](https://github.com/alandtse/tesla/commit/57d6095a2b6cc17e57317eef800261b4bb47bf8c)) + +- Add solar power, grid power, load power sensors ([`57d6095`](https://github.com/alandtse/tesla/commit/57d6095a2b6cc17e57317eef800261b4bb47bf8c)) ## v2.3.1 (2022-07-10) + ### Fix -* Use json in post requests ([`867475f`](https://github.com/alandtse/tesla/commit/867475f94dd341f58ea0692e289abe2c895654b5)) + +- Use json in post requests ([`867475f`](https://github.com/alandtse/tesla/commit/867475f94dd341f58ea0692e289abe2c895654b5)) ### Documentation -* Update HACS URL ([#220](https://github.com/alandtse/tesla/issues/220)) ([`d93f36f`](https://github.com/alandtse/tesla/commit/d93f36f052af6ac69795ceff4a7aea73246778d0)) + +- Update HACS URL ([#220](https://github.com/alandtse/tesla/issues/220)) ([`d93f36f`](https://github.com/alandtse/tesla/commit/d93f36f052af6ac69795ceff4a7aea73246778d0)) ## v2.3.0 (2022-05-29) + ### Feature -* Add support for async_remove_config_entry_device ([#218](https://github.com/alandtse/tesla/issues/218)) ([`562c1b0`](https://github.com/alandtse/tesla/commit/562c1b0ce01ced7adb0743a39178a7e9951c5e35)) + +- Add support for async_remove_config_entry_device ([#218](https://github.com/alandtse/tesla/issues/218)) ([`562c1b0`](https://github.com/alandtse/tesla/commit/562c1b0ce01ced7adb0743a39178a7e9951c5e35)) ### Fix -* Improve handling on 0 Watts power reads ([`bf94f3b`](https://github.com/alandtse/tesla/commit/bf94f3b68ad7d55fb48add049b0c5b444adb55f8)) -* Switch to non-deprecated async_get instead ([#217](https://github.com/alandtse/tesla/issues/217)) ([`f82e030`](https://github.com/alandtse/tesla/commit/f82e030fca09b8a45497db5a63d7e37f9ae6f4d9)) -* Use default if scan_interval settings missing ([`0d3d4ce`](https://github.com/alandtse/tesla/commit/0d3d4ce2947d311a6664cf77f97d9ab88433666a)) + +- Improve handling on 0 Watts power reads ([`bf94f3b`](https://github.com/alandtse/tesla/commit/bf94f3b68ad7d55fb48add049b0c5b444adb55f8)) +- Switch to non-deprecated async_get instead ([#217](https://github.com/alandtse/tesla/issues/217)) ([`f82e030`](https://github.com/alandtse/tesla/commit/f82e030fca09b8a45497db5a63d7e37f9ae6f4d9)) +- Use default if scan_interval settings missing ([`0d3d4ce`](https://github.com/alandtse/tesla/commit/0d3d4ce2947d311a6664cf77f97d9ab88433666a)) ## v2.2.1 (2022-05-02) + ### Fix -* Check vin before adjusting climate devices ([#208](https://github.com/alandtse/tesla/issues/208)) ([`5c81955`](https://github.com/alandtse/tesla/commit/5c819554ef3d81446066262b4435066d17cf7a96)) + +- Check vin before adjusting climate devices ([#208](https://github.com/alandtse/tesla/issues/208)) ([`5c81955`](https://github.com/alandtse/tesla/commit/5c819554ef3d81446066262b4435066d17cf7a96)) ## v2.2.0 (2022-04-30) + ### Feature -* Enable heated seat and steering wheel entities automatically ([#205](https://github.com/alandtse/tesla/issues/205)) ([`ed975f3`](https://github.com/alandtse/tesla/commit/ed975f35fb7c6d33f2dc4b96a6862374279fe091)) + +- Enable heated seat and steering wheel entities automatically ([#205](https://github.com/alandtse/tesla/issues/205)) ([`ed975f3`](https://github.com/alandtse/tesla/commit/ed975f35fb7c6d33f2dc4b96a6862374279fe091)) ## v2.1.1 (2022-04-24) diff --git a/README.md b/README.md index e22c202d..c6338754 100644 --- a/README.md +++ b/README.md @@ -47,18 +47,17 @@ This integration provides the following entities for vehicles: - Binary sensors - charger connection, charging status, car online, parking brake, car asleep, and door status. - Buttons - horn, flash lights, wake up1, force data update1, trigger HomeLink, and remote start. **Note:** The HomeLink button is disabled by default as some vehicles don't have this option. Enable via configuration/entities if desired. - Climate - turn HVAC on/off, set target temperature, set preset modes (defrost, keep on, dog mode and camp mode). -- Device tracker - car location1, and active route destination. +- Device tracker - car location1, and active route destination. - Cover - Charger door, frunk, trunk, and windows. - Locks - door lock, and charge port latch lock. -**Note:** Set `state` to `heat_cool` or `off` to enable/disable your Tesla's climate system via a scene. + **Note:** Set `state` to `heat_cool` or `off` to enable/disable your Tesla's climate system via a scene. - Selects - seat heaters and cabin overheat protection2. **Note:** Turning on a heated seat will cause the climate to turn on. - Sensors - battery level, charge rate, energy added, charger power, inside/outside temperature, odometer, estimated range, time charge complete, TPMS pressure, active route arrival time and distance to arrival. - Switches - heated steering wheel, charger, sentry mode, polling, and valet mode.1. - Update - software update2 -1 *Diagnostics entities.*
-2 *Configuration entities.* - +1 _Diagnostics entities._
+2 _Configuration entities._ This integration provides the following entities for energy sites: diff --git a/custom_components/tesla_custom/__init__.py b/custom_components/tesla_custom/__init__.py index ad5632b8..57482708 100644 --- a/custom_components/tesla_custom/__init__.py +++ b/custom_components/tesla_custom/__init__.py @@ -26,8 +26,8 @@ from .config_flow import CannotConnect, InvalidAuth, validate_input from .const import ( CONF_EXPIRATION, - CONF_INCLUDE_VEHICLES, CONF_INCLUDE_ENERGYSITES, + CONF_INCLUDE_VEHICLES, CONF_POLLING_POLICY, CONF_WAKE_ON_START, DATA_LISTENER, @@ -121,7 +121,7 @@ def _update_entry(email, data=None, options=None): async def async_setup_entry(hass, config_entry): """Set up Tesla as config entry.""" - # pylint: disable=too-many-locals + # pylint: disable=too-many-locals,too-many-statements hass.data.setdefault(DOMAIN, {}) config = config_entry.data # Because users can have multiple accounts, we always diff --git a/custom_components/tesla_custom/base.py b/custom_components/tesla_custom/base.py index 1f79cab0..b6b2b727 100644 --- a/custom_components/tesla_custom/base.py +++ b/custom_components/tesla_custom/base.py @@ -1,13 +1,12 @@ """Support for Tesla cars and energy sites.""" -from teslajsonpy.car import TeslaCar -from teslajsonpy.const import RESOURCE_TYPE_BATTERY -from teslajsonpy.energy import EnergySite - -from homeassistant.util.unit_system import METRIC_SYSTEM, US_CUSTOMARY_SYSTEM from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.update_coordinator import CoordinatorEntity from homeassistant.util import slugify +from homeassistant.util.unit_system import METRIC_SYSTEM, US_CUSTOMARY_SYSTEM +from teslajsonpy.car import TeslaCar +from teslajsonpy.const import RESOURCE_TYPE_BATTERY +from teslajsonpy.energy import EnergySite from . import TeslaDataUpdateCoordinator from .const import ATTRIBUTION, DOMAIN @@ -122,7 +121,6 @@ def device_info(self) -> DeviceInfo: @property def assumed_state(self) -> bool: - # pylint: disable=protected-access """Return whether the data is from an online vehicle.""" return not self._coordinator.controller.is_car_online(vin=self._car.vin) and ( self._coordinator.controller.get_last_update_time(vin=self._car.vin) diff --git a/custom_components/tesla_custom/binary_sensor.py b/custom_components/tesla_custom/binary_sensor.py index 8b9b7441..c2e9034f 100644 --- a/custom_components/tesla_custom/binary_sensor.py +++ b/custom_components/tesla_custom/binary_sensor.py @@ -1,15 +1,14 @@ """Support for Tesla binary sensors.""" import logging -from teslajsonpy.car import TeslaCar -from teslajsonpy.const import GRID_ACTIVE, RESOURCE_TYPE_BATTERY -from teslajsonpy.energy import PowerwallSite - from homeassistant.components.binary_sensor import ( BinarySensorDeviceClass, BinarySensorEntity, ) from homeassistant.core import HomeAssistant +from teslajsonpy.car import TeslaCar +from teslajsonpy.const import GRID_ACTIVE, RESOURCE_TYPE_BATTERY +from teslajsonpy.energy import PowerwallSite from . import TeslaDataUpdateCoordinator from .base import TeslaCarEntity, TeslaEnergyEntity @@ -278,6 +277,7 @@ def is_on(self): @property def extra_state_attributes(self): """Return device state attributes.""" + # pylint: disable=protected-access timestamp = self._car._vehicle_data.get("charge_state", {}).get( "scheduled_charging_start_time" ) @@ -316,6 +316,7 @@ def is_on(self): @property def extra_state_attributes(self): """Return device state attributes.""" + # pylint: disable=protected-access timestamp = self._car._vehicle_data.get("charge_state", {}).get( "scheduled_departure_time" ) @@ -348,11 +349,13 @@ def __init__( @property def is_on(self): """Return True if user present enebaled.""" + # pylint: disable=protected-access return self._car._vehicle_data.get("vehicle_state", {}).get("is_user_present") @property def extra_state_attributes(self): """Return device state attributes.""" + # pylint: disable=protected-access user_id = str(self._car._vehicle_data.get("user_id")) return {"user_id": user_id} diff --git a/custom_components/tesla_custom/button.py b/custom_components/tesla_custom/button.py index 94525d9b..11a0c657 100644 --- a/custom_components/tesla_custom/button.py +++ b/custom_components/tesla_custom/button.py @@ -1,11 +1,10 @@ """Support for Tesla buttons.""" import logging -from teslajsonpy.car import TeslaCar - from homeassistant.components.button import ButtonEntity from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import EntityCategory +from teslajsonpy.car import TeslaCar from . import TeslaDataUpdateCoordinator from .base import TeslaCarEntity @@ -71,7 +70,7 @@ async def async_press(self) -> None: class TeslaCarWakeUp(TeslaCarEntity, ButtonEntity): - """Representation of a Tesla car wake up button""" + """Representation of a Tesla car wake up button.""" def __init__( self, @@ -138,7 +137,7 @@ def __init__( @property def available(self) -> bool: - """Return True if Homelink devices are nearby""" + """Return True if Homelink devices are nearby.""" return super().available and self._car.homelink_nearby async def async_press(self): diff --git a/custom_components/tesla_custom/climate.py b/custom_components/tesla_custom/climate.py index cbf5b840..e1390736 100644 --- a/custom_components/tesla_custom/climate.py +++ b/custom_components/tesla_custom/climate.py @@ -1,8 +1,6 @@ """Support for Tesla climate.""" import logging -from teslajsonpy.car import TeslaCar - from homeassistant.components.climate import ClimateEntity from homeassistant.components.climate.const import ( DEFAULT_MAX_TEMP, @@ -14,6 +12,7 @@ ) from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS from homeassistant.core import HomeAssistant +from teslajsonpy.car import TeslaCar from . import TeslaDataUpdateCoordinator from .base import TeslaCarEntity @@ -109,7 +108,7 @@ def max_temp(self): @property def min_temp(self): - """Return min temperature""" + """Return min temperature.""" if self._car.min_avail_temp: return self._car.min_avail_temp diff --git a/custom_components/tesla_custom/config_flow.py b/custom_components/tesla_custom/config_flow.py index 9219e55b..cf424509 100644 --- a/custom_components/tesla_custom/config_flow.py +++ b/custom_components/tesla_custom/config_flow.py @@ -24,16 +24,16 @@ ATTR_POLLING_POLICY_CONNECTED, ATTR_POLLING_POLICY_NORMAL, CONF_EXPIRATION, - CONF_INCLUDE_VEHICLES, CONF_INCLUDE_ENERGYSITES, + CONF_INCLUDE_VEHICLES, CONF_POLLING_POLICY, CONF_WAKE_ON_START, DEFAULT_POLLING_POLICY, DEFAULT_SCAN_INTERVAL, DEFAULT_WAKE_ON_START, + DOMAIN, MIN_SCAN_INTERVAL, ) -from .const import DOMAIN # pylint: disable=unused-import _LOGGER = logging.getLogger(__name__) diff --git a/custom_components/tesla_custom/cover.py b/custom_components/tesla_custom/cover.py index 44e7451f..f97011d5 100644 --- a/custom_components/tesla_custom/cover.py +++ b/custom_components/tesla_custom/cover.py @@ -1,14 +1,13 @@ """Support for Tesla covers.""" import logging -from teslajsonpy.car import TeslaCar - from homeassistant.components.cover import ( - CoverEntity, CoverDeviceClass, + CoverEntity, CoverEntityFeature, ) from homeassistant.core import HomeAssistant +from teslajsonpy.car import TeslaCar from . import TeslaDataUpdateCoordinator from .base import TeslaCarEntity @@ -173,14 +172,14 @@ def __init__( async def async_close_cover(self, **kwargs): """Send close cover command.""" _LOGGER.debug("Closing cover: %s", self.name) - if self.is_closed == False: + if self.is_closed is False: await self._car.close_windows() await self.async_update_ha_state() async def async_open_cover(self, **kwargs): """Send open cover command.""" _LOGGER.debug("Opening cover: %s", self.name) - if self.is_closed == True: + if self.is_closed is True: await self._car.vent_windows() await self.async_update_ha_state() diff --git a/custom_components/tesla_custom/device_tracker.py b/custom_components/tesla_custom/device_tracker.py index b609afc3..57d6d7a9 100644 --- a/custom_components/tesla_custom/device_tracker.py +++ b/custom_components/tesla_custom/device_tracker.py @@ -1,11 +1,10 @@ """Support for Tesla device tracker.""" import logging -from teslajsonpy.car import TeslaCar - from homeassistant.components.device_tracker import SOURCE_TYPE_GPS from homeassistant.components.device_tracker.config_entry import TrackerEntity from homeassistant.core import HomeAssistant +from teslajsonpy.car import TeslaCar from . import TeslaDataUpdateCoordinator from .base import TeslaCarEntity diff --git a/custom_components/tesla_custom/lock.py b/custom_components/tesla_custom/lock.py index 5a4b159e..9b4ba91a 100644 --- a/custom_components/tesla_custom/lock.py +++ b/custom_components/tesla_custom/lock.py @@ -1,13 +1,9 @@ """Support for Tesla locks.""" import logging -from teslajsonpy.car import TeslaCar - -from homeassistant.components.lock import ( - LockEntity, - LockEntityFeature, -) +from homeassistant.components.lock import LockEntity, LockEntityFeature from homeassistant.core import HomeAssistant +from teslajsonpy.car import TeslaCar from . import TeslaDataUpdateCoordinator from .base import TeslaCarEntity diff --git a/custom_components/tesla_custom/manifest.json b/custom_components/tesla_custom/manifest.json index a6945a4c..bb0576e5 100644 --- a/custom_components/tesla_custom/manifest.json +++ b/custom_components/tesla_custom/manifest.json @@ -4,15 +4,9 @@ "config_flow": true, "documentation": "https://github.com/alandtse/tesla/wiki", "issue_tracker": "https://github.com/alandtse/tesla/issues", - "requirements": [ - "teslajsonpy==3.6.0" - ], - "codeowners": [ - "@alandtse" - ], - "dependencies": [ - "http" - ], + "requirements": ["teslajsonpy==3.7.1"], + "codeowners": ["@alandtse"], + "dependencies": ["http"], "dhcp": [ { "hostname": "tesla_*", diff --git a/custom_components/tesla_custom/number.py b/custom_components/tesla_custom/number.py index 957fb84c..91837567 100644 --- a/custom_components/tesla_custom/number.py +++ b/custom_components/tesla_custom/number.py @@ -1,4 +1,8 @@ """Support for Tesla numbers.""" +from homeassistant.components.number import NumberEntity, NumberMode +from homeassistant.const import ELECTRIC_CURRENT_AMPERE, PERCENTAGE +from homeassistant.core import HomeAssistant +from homeassistant.helpers.icon import icon_for_battery_level from teslajsonpy.car import TeslaCar from teslajsonpy.const import ( BACKUP_RESERVE_MAX, @@ -8,11 +12,6 @@ ) from teslajsonpy.energy import PowerwallSite -from homeassistant.components.number import NumberEntity, NumberMode -from homeassistant.core import HomeAssistant -from homeassistant.const import ELECTRIC_CURRENT_AMPERE, PERCENTAGE -from homeassistant.helpers.icon import icon_for_battery_level - from . import TeslaDataUpdateCoordinator from .base import TeslaCarEntity, TeslaEnergyEntity from .const import DOMAIN diff --git a/custom_components/tesla_custom/select.py b/custom_components/tesla_custom/select.py index 515f72e2..13c95c2e 100644 --- a/custom_components/tesla_custom/select.py +++ b/custom_components/tesla_custom/select.py @@ -1,13 +1,12 @@ """Support for Tesla selects.""" import logging -from teslajsonpy.car import TeslaCar -from teslajsonpy.const import RESOURCE_TYPE_BATTERY -from teslajsonpy.energy import PowerwallSite, SolarPowerwallSite - from homeassistant.components.select import SelectEntity from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import EntityCategory +from teslajsonpy.car import TeslaCar +from teslajsonpy.const import RESOURCE_TYPE_BATTERY +from teslajsonpy.energy import PowerwallSite, SolarPowerwallSite from . import TeslaDataUpdateCoordinator from .base import TeslaCarEntity, TeslaEnergyEntity @@ -260,12 +259,13 @@ async def async_select_option(self, option: str, **kwargs): await self.async_update_ha_state() @property - def current_option(self): + def current_option(self) -> str: """Return current energy export rule setting.""" if self._energysite.export_rule == "pv_only": return EXPORT_RULE[0] if self._energysite.export_rule == "battery_ok": return EXPORT_RULE[1] + return "" class TeslaEnergyOperationMode(TeslaEnergyEntity, SelectEntity): @@ -295,7 +295,7 @@ async def async_select_option(self, option: str, **kwargs): await self.async_update_ha_state() @property - def current_option(self): + def current_option(self) -> str: """Return current operation mode setting.""" if self._energysite.operation_mode == "self_consumption": return OPERATION_MODE[0] @@ -303,3 +303,4 @@ def current_option(self): return OPERATION_MODE[1] if self._energysite.operation_mode == "backup": return OPERATION_MODE[2] + return "" diff --git a/custom_components/tesla_custom/sensor.py b/custom_components/tesla_custom/sensor.py index 300d1936..f347744d 100644 --- a/custom_components/tesla_custom/sensor.py +++ b/custom_components/tesla_custom/sensor.py @@ -3,10 +3,6 @@ from datetime import datetime, timedelta from typing import Optional -from teslajsonpy.car import TeslaCar -from teslajsonpy.const import RESOURCE_TYPE_SOLAR, RESOURCE_TYPE_BATTERY -from teslajsonpy.energy import EnergySite, PowerwallSite - from homeassistant.components.sensor import ( SensorDeviceClass, SensorEntity, @@ -18,8 +14,8 @@ LENGTH_KILOMETERS, LENGTH_MILES, PERCENTAGE, - POWER_WATT, POWER_KILO_WATT, + POWER_WATT, PRESSURE_BAR, PRESSURE_PSI, SPEED_MILES_PER_HOUR, @@ -27,8 +23,11 @@ ) from homeassistant.core import HomeAssistant from homeassistant.helpers.icon import icon_for_battery_level -from homeassistant.util.unit_conversion import DistanceConverter from homeassistant.util import dt +from homeassistant.util.unit_conversion import DistanceConverter +from teslajsonpy.car import TeslaCar +from teslajsonpy.const import RESOURCE_TYPE_BATTERY, RESOURCE_TYPE_SOLAR +from teslajsonpy.energy import EnergySite, PowerwallSite from . import TeslaDataUpdateCoordinator from .base import TeslaCarEntity, TeslaEnergyEntity @@ -322,6 +321,7 @@ def native_value(self) -> float: @property def extra_state_attributes(self): """Return device state attributes.""" + # pylint: disable=protected-access est_battery_range = self._car._vehicle_data.get("charge_state", {}).get( "est_battery_range" ) @@ -410,6 +410,7 @@ def native_value(self) -> float: return round(self._energysite.load_power) if self.type == "battery power": return round(self._energysite.battery_power) + return 0 class TeslaEnergyBattery(TeslaEnergyEntity, SensorEntity): @@ -580,6 +581,7 @@ def native_value(self) -> float: @property def extra_state_attributes(self): """Return device state attributes.""" + # pylint: disable=protected-access timestamp = self._car._vehicle_data.get("vehicle_state", {}).get( TPMS_SENSOR_ATTR.get(self._tpms_sensor) ) @@ -612,8 +614,7 @@ def native_value(self) -> Optional[datetime]: """Return route arrival time.""" if self._car.active_route_minutes_to_arrival is None: return self._datetime_value - else: - min_duration = round(float(self._car.active_route_minutes_to_arrival), 2) + min_duration = round(float(self._car.active_route_minutes_to_arrival), 2) utcnow = dt.utcnow() if self._last_known_value != min_duration: diff --git a/custom_components/tesla_custom/services.py b/custom_components/tesla_custom/services.py index 0dc923dc..c2157f06 100644 --- a/custom_components/tesla_custom/services.py +++ b/custom_components/tesla_custom/services.py @@ -3,13 +3,12 @@ SPDX-License-Identifier: Apache-2.0 """ import logging -import voluptuous as vol - -from teslajsonpy import Controller from homeassistant.const import ATTR_COMMAND, CONF_EMAIL, CONF_SCAN_INTERVAL from homeassistant.core import callback from homeassistant.helpers import config_validation as cv +from teslajsonpy import Controller +import voluptuous as vol from .const import ( ATTR_PARAMETERS, @@ -113,12 +112,12 @@ async def api(call): async def set_update_interval(call): """Handle api service request. - Arguments: + Arguments call.CONF_EMAIL {str: ""} -- email, optional call.ATTR_VIN {str: ""} -- vehicle VIN, optional call.CONF_SCAN_INTERVAL {int: 660} -- New scan interval - Returns: + Returns bool -- True if new interval is set """ diff --git a/custom_components/tesla_custom/switch.py b/custom_components/tesla_custom/switch.py index 7a7016d6..a71564de 100644 --- a/custom_components/tesla_custom/switch.py +++ b/custom_components/tesla_custom/switch.py @@ -1,11 +1,10 @@ """Support for Tesla switches.""" import logging -from teslajsonpy.car import TeslaCar - from homeassistant.components.switch import SwitchEntity from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import EntityCategory +from teslajsonpy.car import TeslaCar from . import TeslaDataUpdateCoordinator from .base import TeslaCarEntity @@ -48,7 +47,7 @@ def __init__( @property def available(self) -> bool: - """Return True if steering wheel heater is available""" + """Return True if steering wheel heater is available.""" return super().available and self._car.steering_wheel_heater @property @@ -151,7 +150,7 @@ def __init__( @property def available(self) -> bool: - """Return True if sentry mode switch is available""" + """Return True if sentry mode switch is available.""" return super().available and self._car.sentry_mode_available @property @@ -197,6 +196,7 @@ def is_on(self): async def async_turn_on(self, **kwargs): """Send the on command.""" + # pylint: disable=protected-access if self._car._vehicle_data.get("vehicle_state", {}).get("valet_pin_needed"): _LOGGER.debug("Pin required for valet mode, set pin in vehicle or app.") else: @@ -205,6 +205,7 @@ async def async_turn_on(self, **kwargs): async def async_turn_off(self, **kwargs): """Send the off command.""" + # pylint: disable=protected-access if self._car._vehicle_data.get("vehicle_state", {}).get("valet_pin_needed"): _LOGGER.debug("Pin required for valet mode, set pin in vehicle or app.") else: diff --git a/custom_components/tesla_custom/translations/da.json b/custom_components/tesla_custom/translations/da.json index 2954001f..f2634ab4 100644 --- a/custom_components/tesla_custom/translations/da.json +++ b/custom_components/tesla_custom/translations/da.json @@ -34,4 +34,3 @@ } } } - diff --git a/custom_components/tesla_custom/update.py b/custom_components/tesla_custom/update.py index 46364be7..2667fafe 100644 --- a/custom_components/tesla_custom/update.py +++ b/custom_components/tesla_custom/update.py @@ -1,10 +1,9 @@ """Support for Tesla update.""" from typing import Any -from teslajsonpy.car import TeslaCar - from homeassistant.components.update import UpdateEntity, UpdateEntityFeature from homeassistant.core import HomeAssistant +from teslajsonpy.car import TeslaCar from . import TeslaDataUpdateCoordinator from .base import TeslaCarEntity @@ -60,8 +59,7 @@ def supported_features(self): and self._car.software_update.get("status") in INSTALLABLE_STATUSES ): return UpdateEntityFeature.INSTALL | UpdateEntityFeature.PROGRESS - else: - return UpdateEntityFeature.PROGRESS + return UpdateEntityFeature.PROGRESS @property def release_url(self) -> str: diff --git a/info.md b/info.md index 97019d13..d0d70f28 100644 --- a/info.md +++ b/info.md @@ -17,11 +17,12 @@ A fork of the [official Tesla integration](https://www.home-assistant.io/integra This is the successor to the core app which was removed due to Tesla login issues. Do not report issues to Home Assistant. To use the component, you will need an application to generate a Tesla refresh token: -- Android: [Tesla Tokens](https://play.google.com/store/apps/details?id=net.leveugle.teslatokens) -- iOS: [Auth App for Tesla](https://apps.apple.com/us/app/auth-app-for-tesla/id1552058613) -- TeslaFi: [Tesla v3 API Tokens](https://support.teslafi.com/en/communities/1/topics/16979-tesla-v3-api-tokens) -- Chromium/Edge: [Chromium Tesla Token Generator](https://github.com/DoctorMcKay/chromium-tesla-token-generator) -{% if not installed %} + +- Android: [Tesla Tokens](https://play.google.com/store/apps/details?id=net.leveugle.teslatokens) +- iOS: [Auth App for Tesla](https://apps.apple.com/us/app/auth-app-for-tesla/id1552058613) +- TeslaFi: [Tesla v3 API Tokens](https://support.teslafi.com/en/communities/1/topics/16979-tesla-v3-api-tokens) +- Chromium/Edge: [Chromium Tesla Token Generator](https://github.com/DoctorMcKay/chromium-tesla-token-generator) + {% if not installed %} ## Installation diff --git a/poetry.lock b/poetry.lock index 38889705..c2066f15 100644 --- a/poetry.lock +++ b/poetry.lock @@ -653,7 +653,6 @@ python-versions = ">=3.6" files = [ {file = "cryptography-38.0.3-cp36-abi3-macosx_10_10_universal2.whl", hash = "sha256:984fe150f350a3c91e84de405fe49e688aa6092b3525f407a18b9646f6612320"}, {file = "cryptography-38.0.3-cp36-abi3-macosx_10_10_x86_64.whl", hash = "sha256:ed7b00096790213e09eb11c97cc6e2b757f15f3d2f85833cd2d3ec3fe37c1722"}, - {file = "cryptography-38.0.3-cp36-abi3-macosx_10_12_universal2.whl", hash = "sha256:726e3a1bfee0e919b278c8f766fdcf1fe30f8e6feea590e3f248d3636b58ffb3"}, {file = "cryptography-38.0.3-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl", hash = "sha256:bbf203f1a814007ce24bd4d51362991d5cb90ba0c177a9c08825f2cc304d871f"}, {file = "cryptography-38.0.3-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:554bec92ee7d1e9d10ded2f7e92a5d70c1f74ba9524947c0ba0c850c7b011828"}, {file = "cryptography-38.0.3-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b1b52c9e5f8aa2b802d48bd693190341fae201ea51c7a167d69fc48b60e8a959"}, @@ -976,14 +975,14 @@ smmap = ">=3.0.1,<6" [[package]] name = "gitpython" -version = "3.1.29" +version = "3.1.30" description = "GitPython is a python library used to interact with Git repositories" category = "dev" optional = false python-versions = ">=3.7" files = [ - {file = "GitPython-3.1.29-py3-none-any.whl", hash = "sha256:41eea0deec2deea139b459ac03656f0dd28fc4a3387240ec1d3c259a2c47850f"}, - {file = "GitPython-3.1.29.tar.gz", hash = "sha256:cc36bfc4a3f913e66805a28e84703e419d9c264c1077e537b54f0e1af85dbefd"}, + {file = "GitPython-3.1.30-py3-none-any.whl", hash = "sha256:cd455b0000615c60e286208ba540271af9fe531fa6a87cc590a7298785ab2882"}, + {file = "GitPython-3.1.30.tar.gz", hash = "sha256:769c2d83e13f5d938b7688479da374c4e3d49f71549aaf462b646db9602ea6f8"}, ] [package.dependencies] @@ -2753,7 +2752,7 @@ greenlet = {version = "!=0.4.17", markers = "python_version >= \"3\" and (platfo [package.extras] aiomysql = ["aiomysql", "greenlet (!=0.4.17)"] -aiosqlite = ["aiosqlite", "greenlet (!=0.4.17)", "typing_extensions (!=3.10.0.1)"] +aiosqlite = ["aiosqlite", "greenlet (!=0.4.17)", "typing-extensions (!=3.10.0.1)"] asyncio = ["greenlet (!=0.4.17)"] asyncmy = ["asyncmy (>=0.2.3,!=0.2.4)", "greenlet (!=0.4.17)"] mariadb-connector = ["mariadb (>=1.0.1,!=1.1.2)"] @@ -2763,14 +2762,14 @@ mssql-pyodbc = ["pyodbc"] mypy = ["mypy (>=0.910)", "sqlalchemy2-stubs"] mysql = ["mysqlclient (>=1.4.0)", "mysqlclient (>=1.4.0,<2)"] mysql-connector = ["mysql-connector-python"] -oracle = ["cx_oracle (>=7)", "cx_oracle (>=7,<8)"] +oracle = ["cx-oracle (>=7)", "cx-oracle (>=7,<8)"] postgresql = ["psycopg2 (>=2.7)"] postgresql-asyncpg = ["asyncpg", "greenlet (!=0.4.17)"] postgresql-pg8000 = ["pg8000 (>=1.16.6,!=1.29.0)"] postgresql-psycopg2binary = ["psycopg2-binary"] postgresql-psycopg2cffi = ["psycopg2cffi"] pymysql = ["pymysql", "pymysql (<1)"] -sqlcipher = ["sqlcipher3_binary"] +sqlcipher = ["sqlcipher3-binary"] [[package]] name = "stdlib-list" @@ -2834,14 +2833,14 @@ tests = ["pytest", "pytest-cov"] [[package]] name = "teslajsonpy" -version = "3.7.0" +version = "3.7.1" description = "A library to work with Tesla API." category = "main" optional = false python-versions = ">=3.7,<4.0" files = [ - {file = "teslajsonpy-3.7.0-py3-none-any.whl", hash = "sha256:188379851ff82d356f0f9be21d26d76a7bccd18448b83027f4597ddb59913844"}, - {file = "teslajsonpy-3.7.0.tar.gz", hash = "sha256:0188db435ddcd6878fc73532b744355aad0c1b7f0c33bf663f0aee970fcf70b9"}, + {file = "teslajsonpy-3.7.1-py3-none-any.whl", hash = "sha256:60854dbfb6612913b5d6141685746d55afc333ed37dcef6cc8cf1fd160bef8a8"}, + {file = "teslajsonpy-3.7.1.tar.gz", hash = "sha256:00ac95054f3a9ceb51814dd9e9aa91cf33b761081bf124bf111c2845bd311fb9"}, ] [package.dependencies] @@ -3185,4 +3184,4 @@ testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools" [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "0e6da8b6ce787b1b68b9c41df095580f7f95de272a3fdc29fe89395093b4e153" +content-hash = "4e52cdf2918a009b9383836bdc473cc60164bbcd87c48d7f71a950b9ee06523b" diff --git a/pyproject.toml b/pyproject.toml index 9d7f6a08..1718a2e4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,10 +7,10 @@ license = "Apache-2.0" [tool.poetry.dependencies] python = "^3.10" -teslajsonpy = "^3.6.0" +teslajsonpy = "^3.7.1" -[tool.poetry.dev-dependencies] +[tool.poetry.group.dev.dependencies] homeassistant = ">=2022.11.0" pytest-homeassistant-custom-component = ">=0.3.1" bandit = ">=1.7.0" diff --git a/tests/common.py b/tests/common.py index 0ddd5672..862d2ed4 100644 --- a/tests/common.py +++ b/tests/common.py @@ -12,14 +12,13 @@ from homeassistant.setup import async_setup_component from pytest_homeassistant_custom_component.common import MockConfigEntry from teslajsonpy.car import TeslaCar -from teslajsonpy.energy import SolarSite, SolarPowerwallSite from teslajsonpy.const import AUTH_DOMAIN +from teslajsonpy.energy import SolarPowerwallSite, SolarSite from custom_components.tesla_custom.const import CONF_EXPIRATION, DOMAIN as TESLA_DOMIN from .const import TEST_ACCESS_TOKEN, TEST_TOKEN, TEST_USERNAME, TEST_VALID_EXPIRATION -from .mock_data import car as car_mock_data -from .mock_data import energysite as energysite_mock_data +from .mock_data import car as car_mock_data, energysite as energysite_mock_data def setup_mock_controller(mock_controller): diff --git a/tests/test_binary_sensor.py b/tests/test_binary_sensor.py index a24856d2..eab75c64 100644 --- a/tests/test_binary_sensor.py +++ b/tests/test_binary_sensor.py @@ -4,7 +4,7 @@ DOMAIN as BINARY_SENSOR_DOMAIN, BinarySensorDeviceClass, ) -from homeassistant.const import ATTR_DEVICE_CLASS, STATE_ON, STATE_OFF +from homeassistant.const import ATTR_DEVICE_CLASS, STATE_OFF, STATE_ON from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er diff --git a/tests/test_button.py b/tests/test_button.py index 91f095bd..0d682d55 100644 --- a/tests/test_button.py +++ b/tests/test_button.py @@ -1,9 +1,7 @@ """Tests for the Tesla button.""" from unittest.mock import patch -from homeassistant.components.button import ( - DOMAIN as BUTTON_DOMAIN, -) +from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN from homeassistant.const import ATTR_ENTITY_ID from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er diff --git a/tests/test_climate.py b/tests/test_climate.py index 04630405..5ee8b2fe 100644 --- a/tests/test_climate.py +++ b/tests/test_climate.py @@ -1,9 +1,7 @@ """Tests for the Tesla climate.""" from unittest.mock import patch -from homeassistant.components.climate import ( - DOMAIN as CLIMATE_DOMAIN, -) +from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE, STATE_OFF from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er diff --git a/tests/test_cover.py b/tests/test_cover.py index 5158253a..50b6337b 100644 --- a/tests/test_cover.py +++ b/tests/test_cover.py @@ -2,11 +2,7 @@ from unittest.mock import patch from homeassistant.components.cover import DOMAIN as COVER_DOMAIN -from homeassistant.const import ( - ATTR_ENTITY_ID, - SERVICE_CLOSE_COVER, - SERVICE_OPEN_COVER, -) +from homeassistant.const import ATTR_ENTITY_ID, SERVICE_CLOSE_COVER, SERVICE_OPEN_COVER from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er diff --git a/tests/test_device_tracker.py b/tests/test_device_tracker.py index 59c4caea..6e2782d9 100644 --- a/tests/test_device_tracker.py +++ b/tests/test_device_tracker.py @@ -1,18 +1,13 @@ """Tests for the Tesla device tracker.""" from homeassistant.components.device_tracker import DOMAIN as DEVICE_TRACKER_DOMAIN +from homeassistant.const import STATE_UNKNOWN from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er -from homeassistant.const import ( - STATE_UNKNOWN, -) - from .common import setup_platform - from .mock_data import car as car_mock_data - # async def test_registry_entries(hass: HomeAssistant) -> None: # """Tests devices are registered in the entity registry.""" # await setup_platform(hass, DEVICE_TRACKER_DOMAIN) diff --git a/tests/test_lock.py b/tests/test_lock.py index f9d1c5c2..ac5b9bae 100644 --- a/tests/test_lock.py +++ b/tests/test_lock.py @@ -2,11 +2,7 @@ from unittest.mock import patch from homeassistant.components.lock import DOMAIN as LOCK_DOMAIN -from homeassistant.const import ( - ATTR_ENTITY_ID, - SERVICE_LOCK, - SERVICE_UNLOCK, -) +from homeassistant.const import ATTR_ENTITY_ID, SERVICE_LOCK, SERVICE_UNLOCK from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er diff --git a/tests/test_number.py b/tests/test_number.py index e8ec487f..8be3550b 100644 --- a/tests/test_number.py +++ b/tests/test_number.py @@ -1,16 +1,14 @@ """Tests for the Tesla number.""" from unittest.mock import patch -from teslajsonpy.const import BACKUP_RESERVE_MAX, BACKUP_RESERVE_MIN, CHARGE_CURRENT_MIN - from homeassistant.components.number import DOMAIN as NUMBER_DOMAIN from homeassistant.const import ATTR_ENTITY_ID from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er +from teslajsonpy.const import BACKUP_RESERVE_MAX, BACKUP_RESERVE_MIN, CHARGE_CURRENT_MIN from .common import setup_platform -from .mock_data import car as car_mock_data -from .mock_data import energysite as energysite_mock_data +from .mock_data import car as car_mock_data, energysite as energysite_mock_data async def test_registry_entries(hass: HomeAssistant) -> None: diff --git a/tests/test_sensor.py b/tests/test_sensor.py index a86e8baa..83af4176 100644 --- a/tests/test_sensor.py +++ b/tests/test_sensor.py @@ -2,8 +2,6 @@ from datetime import datetime, timedelta, timezone -from pytest import MonkeyPatch - from homeassistant.components.sensor import ( DOMAIN as SENSOR_DOMAIN, SensorDeviceClass, @@ -30,14 +28,13 @@ from homeassistant.util import dt from homeassistant.util.unit_conversion import ( DistanceConverter, - SpeedConverter, PressureConverter, + SpeedConverter, ) +from pytest import MonkeyPatch from .common import setup_platform -from .mock_data import car as car_mock_data -from .mock_data import energysite as energysite_mock_data - +from .mock_data import car as car_mock_data, energysite as energysite_mock_data ATTR_STATE_CLASS = "state_class" diff --git a/tests/test_switch.py b/tests/test_switch.py index cc995bad..cb27a943 100644 --- a/tests/test_switch.py +++ b/tests/test_switch.py @@ -2,7 +2,7 @@ from unittest.mock import patch from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN -from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_ON, SERVICE_TURN_OFF +from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er diff --git a/tests/test_update.py b/tests/test_update.py index b8c9dba3..a90f13fd 100644 --- a/tests/test_update.py +++ b/tests/test_update.py @@ -1,13 +1,12 @@ """Tests for the Tesla update.""" from unittest.mock import patch -import pytest from homeassistant.components.update import DOMAIN as UPDATE_DOMAIN - from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers import entity_registry as er +import pytest from .common import setup_platform from .mock_data import car as car_mock_data @@ -103,7 +102,6 @@ async def test_status_available(hass: HomeAssistant) -> None: with patch( "teslajsonpy.car.TeslaCar.schedule_software_update" ) as mock_schedule_software_update: - assert await hass.services.async_call( UPDATE_DOMAIN, "install", @@ -140,7 +138,6 @@ async def test_status_scheduled(hass: HomeAssistant) -> None: with patch( "teslajsonpy.car.TeslaCar.schedule_software_update" ) as mock_schedule_software_update: - assert await hass.services.async_call( UPDATE_DOMAIN, "install",