Skip to content

Commit

Permalink
Merge pull request #850 from alandtse/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse authored Feb 10, 2024
2 parents ad71026 + 3c52a67 commit a74b6eb
Show file tree
Hide file tree
Showing 31 changed files with 298 additions and 230 deletions.
1 change: 1 addition & 0 deletions custom_components/tesla_custom/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for Tesla cars."""

import asyncio
from datetime import timedelta
from functools import partial
Expand Down
1 change: 1 addition & 0 deletions custom_components/tesla_custom/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for Tesla binary sensors."""

import logging

from homeassistant.components.binary_sensor import (
Expand Down
1 change: 1 addition & 0 deletions custom_components/tesla_custom/button.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for Tesla buttons."""

import logging

from homeassistant.components.button import ButtonEntity
Expand Down
1 change: 1 addition & 0 deletions custom_components/tesla_custom/climate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for Tesla climate."""

import logging

from homeassistant.components.climate import (
Expand Down
1 change: 1 addition & 0 deletions custom_components/tesla_custom/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tesla Config Flow."""

from http import HTTPStatus
import logging

Expand Down
1 change: 1 addition & 0 deletions custom_components/tesla_custom/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Const file for Tesla cars."""

VERSION = "3.19.7"
CONF_EXPIRATION = "expiration"
CONF_INCLUDE_VEHICLES = "include_vehicles"
Expand Down
1 change: 1 addition & 0 deletions custom_components/tesla_custom/cover.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for Tesla covers."""

import logging

from homeassistant.components.cover import (
Expand Down
1 change: 1 addition & 0 deletions custom_components/tesla_custom/device_tracker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for Tesla device tracker."""

import logging

from homeassistant.components.device_tracker import SourceType
Expand Down
1 change: 1 addition & 0 deletions custom_components/tesla_custom/lock.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for Tesla locks."""

import logging

from homeassistant.components.lock import LockEntity, LockEntityFeature
Expand Down
2 changes: 1 addition & 1 deletion custom_components/tesla_custom/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/alandtse/tesla/issues",
"loggers": ["teslajsonpy"],
"requirements": ["teslajsonpy==3.9.9"],
"requirements": ["teslajsonpy==3.9.10"],
"version": "3.19.7"
}
1 change: 1 addition & 0 deletions custom_components/tesla_custom/number.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for Tesla numbers."""

from homeassistant.components.number import NumberEntity, NumberMode
from homeassistant.const import PERCENTAGE, UnitOfElectricCurrent
from homeassistant.core import HomeAssistant
Expand Down
1 change: 1 addition & 0 deletions custom_components/tesla_custom/select.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for Tesla selects."""

import logging

from homeassistant.components.select import SelectEntity
Expand Down
8 changes: 5 additions & 3 deletions custom_components/tesla_custom/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,11 @@ def extra_state_attributes(self):
"Energy at arrival": car.active_route_energy_at_arrival,
"Minutes traffic delay": minutes,
"Destination": car.active_route_destination,
"Minutes to arrival": None
if car.active_route_minutes_to_arrival is None
else round(float(car.active_route_minutes_to_arrival), 2),
"Minutes to arrival": (
None
if car.active_route_minutes_to_arrival is None
else round(float(car.active_route_minutes_to_arrival), 2)
),
}


Expand Down
1 change: 1 addition & 0 deletions custom_components/tesla_custom/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
SPDX-License-Identifier: Apache-2.0
"""

import logging

from homeassistant.const import ATTR_COMMAND, CONF_EMAIL, CONF_SCAN_INTERVAL
Expand Down
1 change: 1 addition & 0 deletions custom_components/tesla_custom/switch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for Tesla switches."""

import logging

from homeassistant.components.switch import SwitchEntity
Expand Down
1 change: 1 addition & 0 deletions custom_components/tesla_custom/text.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for Tesla numbers."""

from homeassistant.components.text import TextEntity, TextMode
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
Expand Down
1 change: 1 addition & 0 deletions custom_components/tesla_custom/update.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Support for Tesla update."""

from typing import Any

from homeassistant.components.update import UpdateEntity, UpdateEntityFeature
Expand Down
420 changes: 225 additions & 195 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "Apache-2.0"

[tool.poetry.dependencies]
python = "^3.10"
teslajsonpy = "3.9.9"
teslajsonpy = "3.9.10"


[tool.poetry.group.dev.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion scripts/setup
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ poetry config virtualenvs.create false
poetry install --no-interaction

# Keep this inline with any requirements that are in manifest.json
pip install git+https://github.com/zabuldon/teslajsonpy.git@dev#teslajsonpy==3.9.9
pip install git+https://github.com/zabuldon/teslajsonpy.git@dev#teslajsonpy==3.9.10
pre-commit install --install-hooks
10 changes: 7 additions & 3 deletions tests/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Common methods used across tests for Tesla."""

from datetime import datetime
from unittest.mock import patch

Expand Down Expand Up @@ -80,9 +81,12 @@ async def setup_platform(hass: HomeAssistant, platform: str) -> MockConfigEntry:

mock_entry.add_to_hass(hass)

with patch("custom_components.tesla_custom.PLATFORMS", [platform]), patch(
"custom_components.tesla_custom.TeslaAPI", autospec=True
) as mock_controller:
with (
patch("custom_components.tesla_custom.PLATFORMS", [platform]),
patch(
"custom_components.tesla_custom.TeslaAPI", autospec=True
) as mock_controller,
):
setup_mock_controller(mock_controller)
assert await async_setup_component(hass, TESLA_DOMIN, {})
await hass.async_block_till_done()
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Global fixtures for integration_blueprint integration."""

# Fixtures allow you to replace functions with a Mock object. You can perform
# many options via the Mock to reflect a particular behavior from the original
# function that you want to see without going through the function's actual logic.
Expand Down
1 change: 1 addition & 0 deletions tests/test_button.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the Tesla button."""

from unittest.mock import patch

from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN
Expand Down
17 changes: 9 additions & 8 deletions tests/test_climate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the Tesla climate."""

from unittest.mock import patch

from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN
Expand Down Expand Up @@ -85,10 +86,9 @@ async def test_set_preset_mode(hass: HomeAssistant) -> None:
"""Tests car setting HVAC mode."""
await setup_platform(hass, CLIMATE_DOMAIN)

with patch(
"teslajsonpy.car.TeslaCar.set_max_defrost"
) as mock_set_max_defrost, patch(
"teslajsonpy.car.TeslaCar.defrost_mode", return_value=1
with (
patch("teslajsonpy.car.TeslaCar.set_max_defrost") as mock_set_max_defrost,
patch("teslajsonpy.car.TeslaCar.defrost_mode", return_value=1),
):
# Test set preset_mode "Normal" with defrost_mode != 0
await hass.services.async_call(
Expand All @@ -102,10 +102,11 @@ async def test_set_preset_mode(hass: HomeAssistant) -> None:
)
mock_set_max_defrost.assert_awaited_once_with(False)

with patch(
"teslajsonpy.car.TeslaCar.set_climate_keeper_mode"
) as mock_set_climate_keeper_mode, patch(
"teslajsonpy.car.TeslaCar.climate_keeper_mode", return_value="on"
with (
patch(
"teslajsonpy.car.TeslaCar.set_climate_keeper_mode"
) as mock_set_climate_keeper_mode,
patch("teslajsonpy.car.TeslaCar.climate_keeper_mode", return_value="on"),
):
# Test set preset_mode "Normal" with climate_keeper_mode != 0
await hass.services.async_call(
Expand Down
29 changes: 17 additions & 12 deletions tests/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the Tesla config flow."""

import datetime
from http import HTTPStatus
from unittest.mock import patch
Expand Down Expand Up @@ -47,18 +48,22 @@ async def test_form(hass):
assert result["type"] == "form"
assert result["errors"] == {}

with patch(
"custom_components.tesla_custom.config_flow.TeslaAPI.connect",
return_value={
"refresh_token": TEST_TOKEN,
CONF_ACCESS_TOKEN: TEST_ACCESS_TOKEN,
CONF_EXPIRATION: TEST_VALID_EXPIRATION,
},
), patch(
"custom_components.tesla_custom.async_setup", return_value=True
) as mock_setup, patch(
"custom_components.tesla_custom.async_setup_entry", return_value=True
) as mock_setup_entry:
with (
patch(
"custom_components.tesla_custom.config_flow.TeslaAPI.connect",
return_value={
"refresh_token": TEST_TOKEN,
CONF_ACCESS_TOKEN: TEST_ACCESS_TOKEN,
CONF_EXPIRATION: TEST_VALID_EXPIRATION,
},
),
patch(
"custom_components.tesla_custom.async_setup", return_value=True
) as mock_setup,
patch(
"custom_components.tesla_custom.async_setup_entry", return_value=True
) as mock_setup_entry,
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"], {CONF_TOKEN: TEST_TOKEN, CONF_USERNAME: "[email protected]"}
)
Expand Down
1 change: 1 addition & 0 deletions tests/test_cover.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the Tesla cover."""

from unittest.mock import patch

from homeassistant.components.cover import DOMAIN as COVER_DOMAIN
Expand Down
1 change: 1 addition & 0 deletions tests/test_lock.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the Tesla lock."""

from unittest.mock import patch

from homeassistant.components.lock import DOMAIN as LOCK_DOMAIN
Expand Down
1 change: 1 addition & 0 deletions tests/test_number.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the Tesla number."""

from unittest.mock import patch

from homeassistant.components.number import DOMAIN as NUMBER_DOMAIN
Expand Down
1 change: 1 addition & 0 deletions tests/test_select.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the Tesla select."""

from unittest.mock import patch

from homeassistant.components.select import DOMAIN as SELECT_DOMAIN
Expand Down
16 changes: 10 additions & 6 deletions tests/test_switch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the Tesla switch."""

from unittest.mock import patch

from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
Expand Down Expand Up @@ -71,12 +72,15 @@ async def test_heated_steering(hass: HomeAssistant) -> None:
entity_id = "switch.my_model_s_heated_steering"

# We need to enable the switch for Testing.
with patch(
"custom_components.tesla_custom.switch.TeslaCarHeatedSteeringWheel.entity_registry_enabled_default",
return_value=True,
), patch(
"teslajsonpy.car.TeslaCar.set_heated_steering_wheel"
) as mock_seat_heated_steering_wheel:
with (
patch(
"custom_components.tesla_custom.switch.TeslaCarHeatedSteeringWheel.entity_registry_enabled_default",
return_value=True,
),
patch(
"teslajsonpy.car.TeslaCar.set_heated_steering_wheel"
) as mock_seat_heated_steering_wheel,
):
await setup_platform(hass, SWITCH_DOMAIN)

# Test switch on
Expand Down
1 change: 1 addition & 0 deletions tests/test_update.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the Tesla update."""

from unittest.mock import patch

from homeassistant.components.update import DOMAIN as UPDATE_DOMAIN
Expand Down

0 comments on commit a74b6eb

Please sign in to comment.