diff --git a/.devcontainer/README.md b/.devcontainer/README.md new file mode 100644 index 00000000..b4476875 --- /dev/null +++ b/.devcontainer/README.md @@ -0,0 +1,60 @@ +## Developing with Visual Studio Code + devcontainer + +The easiest way to get started with custom integration development is to use Visual Studio Code with devcontainers. This approach will create a preconfigured development environment with all the tools you need. + +In the container you will have a dedicated Home Assistant core instance running with your custom component code. You can configure this instance by updating the `./devcontainer/configuration.yaml` file. + +**Prerequisites** + +- [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) +- Docker + - For Linux, macOS, or Windows 10 Pro/Enterprise/Education use the [current release version of Docker](https://docs.docker.com/install/) + - Windows 10 Home requires [WSL 2](https://docs.microsoft.com/windows/wsl/wsl2-install) and the current Edge version of Docker Desktop (see instructions [here](https://docs.docker.com/docker-for-windows/wsl-tech-preview/)). This can also be used for Windows Pro/Enterprise/Education. +- [Visual Studio code](https://code.visualstudio.com/) +- [Remote - Containers (VSC Extension)][extension-link] + +[More info about requirements and devcontainer in general](https://code.visualstudio.com/docs/remote/containers#_getting-started) + +[extension-link]: https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers + +**Getting started:** + +1. Fork the repository. +2. Clone the repository to your computer. +3. Open the repository using Visual Studio code. + +When you open this repository with Visual Studio code you are asked to "Reopen in Container", this will start the build of the container. + +_If you don't see this notification, open the command palette and select `Remote-Containers: Reopen Folder in Container`._ + +### Tasks + +The devcontainer comes with some useful tasks to help you with development, you can start these tasks by opening the command palette and select `Tasks: Run Task` then select the task you want to run. + +When a task is currently running (like `Run Home Assistant on port 9123` for the docs), it can be restarted by opening the command palette and selecting `Tasks: Restart Running Task`, then select the task you want to restart. + +The available tasks are: + +| Task | Description | +| ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------- | +| Run Home Assistant on port 9123 | Launch Home Assistant with your custom component code and the configuration defined in `.devcontainer/configuration.yaml`. | +| Run Home Assistant configuration against /config | Check the configuration. | +| Upgrade Home Assistant to latest dev | Upgrade the Home Assistant core version in the container to the latest version of the `dev` branch. | +| Install a specific version of Home Assistant | Install a specific version of Home Assistant core in the container. | + +### Step by Step debugging + +With the development container, +you can test your custom component in Home Assistant with step by step debugging. + +You need to modify the `configuration.yaml` file in `.devcontainer` folder +by uncommenting the line: + +```yaml +# debugpy: +``` + +Then launch the task `Run Home Assistant on port 9123`, and launch the debbuger +with the existing debugging configuration `Python: Attach Local`. + +For more information, look at [the Remote Python Debugger integration documentation](https://www.home-assistant.io/integrations/debugpy/). diff --git a/.devcontainer/configuration.yaml b/.devcontainer/configuration.yaml new file mode 100644 index 00000000..b1b96ce3 --- /dev/null +++ b/.devcontainer/configuration.yaml @@ -0,0 +1,11 @@ +default_config: + +logger: + default: info + logs: + homeassistant.setup: debug + custom_components.tesla_custom: debug + authcaptureproxy: debug + teslajsonpy: debug +# If you need to debug uncommment the line below (doc: https://www.home-assistant.io/integrations/debugpy/) +debugpy: diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..37160cba --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,32 @@ +{ + "image": "ludeeus/container:integration-debian", + "name": "Tesla Custom Component development", + "context": "..", + "appPort": ["9123:8123"], + "postCreateCommand": "container install && pip install poetry && poetry config virtualenvs.create false && poetry install", + "extensions": [ + "ms-python.python", + "github.vscode-pull-request-github", + "ryanluker.vscode-coverage-gutters", + "ms-python.vscode-pylance", + "littlefoxteam.vscode-python", + "bungcip.better-toml", + "redhat.vscode-yaml", + "eamodio.gitlens", + "littlefoxteam.vscode-python-test-adapter" + ], + "settings": { + "files.eol": "\n", + "editor.tabSize": 4, + "terminal.integrated.shell.linux": "/bin/bash", + "python.pythonPath": "/usr/local/python/bin/python", + "python.analysis.autoSearchPaths": false, + "python.linting.pylintEnabled": true, + "python.linting.enabled": true, + "python.formatting.provider": "black", + "editor.formatOnPaste": false, + "editor.formatOnSave": true, + "editor.formatOnType": true, + "files.trimTrailingWhitespace": true + } +} diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml index 7129f516..ae722ae3 100644 --- a/.github/workflows/pull.yml +++ b/.github/workflows/pull.yml @@ -51,7 +51,7 @@ jobs: --timeout=9 \ --durations=10 \ -n auto \ - --cov custom_components.tesla \ + --cov custom_components.tesla_custom \ -o console_output_style=count \ -p no:sugar \ tests diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 9ccd5800..ccbcf9e3 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -54,7 +54,7 @@ jobs: --timeout=9 \ --durations=10 \ -n auto \ - --cov custom_components.tesla \ + --cov custom_components.tesla_custom \ -o console_output_style=count \ -p no:sugar \ tests diff --git a/.github/workflows/semantic_release.yml b/.github/workflows/semantic_release.yml index 41a54670..e572c05c 100644 --- a/.github/workflows/semantic_release.yml +++ b/.github/workflows/semantic_release.yml @@ -54,7 +54,7 @@ jobs: github_token: ${{ secrets.GH_TOKEN }} - name: Zip tesla dir run: | - cd /home/runner/work/tesla/tesla/custom_components/tesla + cd /home/runner/work/tesla/tesla/custom_components/tesla_custom zip tesla.zip -r ./ - name: Set release variable run: | @@ -67,7 +67,7 @@ jobs: uses: svenstaro/upload-release-action@v1-release with: repo_token: ${{ secrets.GH_TOKEN }} - file: /home/runner/work/tesla/tesla/custom_components/tesla/tesla.zip + file: /home/runner/work/tesla/tesla/custom_components/tesla_custom/tesla.zip asset_name: tesla.zip tag: ${{ env.release_version }} overwrite: true diff --git a/.gitignore b/.gitignore index 0fcf9e24..c86115c7 100644 --- a/.gitignore +++ b/.gitignore @@ -71,3 +71,4 @@ deps/deps.jl !.npmignore !/.scrutinizer.yml !/.prospector.yml +!/.devcontainer diff --git a/README.md b/README.md index 0a682245..e164e5e1 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,8 @@ To the extent the official component adds features unrelated to the login, we wi 1. Use HACS after adding this `https://github.com/alandtse/tesla` as a custom repository. Skip to 7. 2. If no HACS, use the tool of choice to open the directory (folder) for your HA configuration (where you find `configuration.yaml`). 3. If you do not have a `custom_components` directory (folder) there, you need to create it. -4. In the `custom_components` directory (folder) create a new folder called `tesla`. -5. Download _all_ the files from the `custom_components/tesla/` directory (folder) in this repository. +4. In the `custom_components` directory (folder) create a new folder called `tesla_custom`. +5. Download _all_ the files from the `custom_components/tesla_custom/` directory (folder) in this repository. 6. Place the files you downloaded in the new directory (folder) you created. 7. Restart Home Assistant. 8. In the HA UI go to "Configuration" -> "Integrations" click "+" and search for "Tesla Custom Integration". If you are replacing core, remove the core integration before installing. diff --git a/custom_components/tesla/__init__.py b/custom_components/tesla_custom/__init__.py similarity index 100% rename from custom_components/tesla/__init__.py rename to custom_components/tesla_custom/__init__.py diff --git a/custom_components/tesla/binary_sensor.py b/custom_components/tesla_custom/binary_sensor.py similarity index 100% rename from custom_components/tesla/binary_sensor.py rename to custom_components/tesla_custom/binary_sensor.py diff --git a/custom_components/tesla/climate.py b/custom_components/tesla_custom/climate.py similarity index 100% rename from custom_components/tesla/climate.py rename to custom_components/tesla_custom/climate.py diff --git a/custom_components/tesla/config_flow.py b/custom_components/tesla_custom/config_flow.py similarity index 100% rename from custom_components/tesla/config_flow.py rename to custom_components/tesla_custom/config_flow.py diff --git a/custom_components/tesla/const.py b/custom_components/tesla_custom/const.py similarity index 97% rename from custom_components/tesla/const.py rename to custom_components/tesla_custom/const.py index d6ea8801..994dbdfd 100644 --- a/custom_components/tesla/const.py +++ b/custom_components/tesla_custom/const.py @@ -2,7 +2,7 @@ VERSION = "0.1.0" CONF_WAKE_ON_START = "enable_wake_on_start" CONF_EXPIRATION = "expiration" -DOMAIN = "tesla" +DOMAIN = "tesla_custom" DATA_LISTENER = "listener" DEFAULT_SCAN_INTERVAL = 660 DEFAULT_WAKE_ON_START = False diff --git a/custom_components/tesla/device_tracker.py b/custom_components/tesla_custom/device_tracker.py similarity index 100% rename from custom_components/tesla/device_tracker.py rename to custom_components/tesla_custom/device_tracker.py diff --git a/custom_components/tesla/lock.py b/custom_components/tesla_custom/lock.py similarity index 100% rename from custom_components/tesla/lock.py rename to custom_components/tesla_custom/lock.py diff --git a/custom_components/tesla/manifest.json b/custom_components/tesla_custom/manifest.json similarity index 88% rename from custom_components/tesla/manifest.json rename to custom_components/tesla_custom/manifest.json index 73706592..a117edf3 100644 --- a/custom_components/tesla/manifest.json +++ b/custom_components/tesla_custom/manifest.json @@ -1,10 +1,10 @@ { - "domain": "tesla", + "domain": "tesla_custom", "name": "Tesla Custom Integration", "config_flow": true, "documentation": "https://github.com/alandtse/tesla", "issue_tracker": "https://github.com/alandtse/tesla/issues", - "requirements": ["teslajsonpy==0.18.0"], + "requirements": ["teslajsonpy~=0.18"], "codeowners": ["@alandtse"], "dependencies": ["http"], "dhcp": [ diff --git a/custom_components/tesla/sensor.py b/custom_components/tesla_custom/sensor.py similarity index 100% rename from custom_components/tesla/sensor.py rename to custom_components/tesla_custom/sensor.py diff --git a/custom_components/tesla/strings.json b/custom_components/tesla_custom/strings.json similarity index 100% rename from custom_components/tesla/strings.json rename to custom_components/tesla_custom/strings.json diff --git a/custom_components/tesla/switch.py b/custom_components/tesla_custom/switch.py similarity index 100% rename from custom_components/tesla/switch.py rename to custom_components/tesla_custom/switch.py diff --git a/custom_components/tesla/tesla_device.py b/custom_components/tesla_custom/tesla_device.py similarity index 100% rename from custom_components/tesla/tesla_device.py rename to custom_components/tesla_custom/tesla_device.py diff --git a/custom_components/tesla/translations/ca.json b/custom_components/tesla_custom/translations/ca.json similarity index 100% rename from custom_components/tesla/translations/ca.json rename to custom_components/tesla_custom/translations/ca.json diff --git a/custom_components/tesla/translations/cs.json b/custom_components/tesla_custom/translations/cs.json similarity index 100% rename from custom_components/tesla/translations/cs.json rename to custom_components/tesla_custom/translations/cs.json diff --git a/custom_components/tesla/translations/da.json b/custom_components/tesla_custom/translations/da.json similarity index 100% rename from custom_components/tesla/translations/da.json rename to custom_components/tesla_custom/translations/da.json diff --git a/custom_components/tesla/translations/de.json b/custom_components/tesla_custom/translations/de.json similarity index 100% rename from custom_components/tesla/translations/de.json rename to custom_components/tesla_custom/translations/de.json diff --git a/custom_components/tesla/translations/en.json b/custom_components/tesla_custom/translations/en.json similarity index 100% rename from custom_components/tesla/translations/en.json rename to custom_components/tesla_custom/translations/en.json diff --git a/custom_components/tesla/translations/es-419.json b/custom_components/tesla_custom/translations/es-419.json similarity index 100% rename from custom_components/tesla/translations/es-419.json rename to custom_components/tesla_custom/translations/es-419.json diff --git a/custom_components/tesla/translations/es.json b/custom_components/tesla_custom/translations/es.json similarity index 100% rename from custom_components/tesla/translations/es.json rename to custom_components/tesla_custom/translations/es.json diff --git a/custom_components/tesla/translations/et.json b/custom_components/tesla_custom/translations/et.json similarity index 100% rename from custom_components/tesla/translations/et.json rename to custom_components/tesla_custom/translations/et.json diff --git a/custom_components/tesla/translations/fr.json b/custom_components/tesla_custom/translations/fr.json similarity index 100% rename from custom_components/tesla/translations/fr.json rename to custom_components/tesla_custom/translations/fr.json diff --git a/custom_components/tesla/translations/he.json b/custom_components/tesla_custom/translations/he.json similarity index 100% rename from custom_components/tesla/translations/he.json rename to custom_components/tesla_custom/translations/he.json diff --git a/custom_components/tesla/translations/hu.json b/custom_components/tesla_custom/translations/hu.json similarity index 100% rename from custom_components/tesla/translations/hu.json rename to custom_components/tesla_custom/translations/hu.json diff --git a/custom_components/tesla/translations/id.json b/custom_components/tesla_custom/translations/id.json similarity index 100% rename from custom_components/tesla/translations/id.json rename to custom_components/tesla_custom/translations/id.json diff --git a/custom_components/tesla/translations/it.json b/custom_components/tesla_custom/translations/it.json similarity index 100% rename from custom_components/tesla/translations/it.json rename to custom_components/tesla_custom/translations/it.json diff --git a/custom_components/tesla/translations/ka.json b/custom_components/tesla_custom/translations/ka.json similarity index 100% rename from custom_components/tesla/translations/ka.json rename to custom_components/tesla_custom/translations/ka.json diff --git a/custom_components/tesla/translations/ko.json b/custom_components/tesla_custom/translations/ko.json similarity index 100% rename from custom_components/tesla/translations/ko.json rename to custom_components/tesla_custom/translations/ko.json diff --git a/custom_components/tesla/translations/lb.json b/custom_components/tesla_custom/translations/lb.json similarity index 100% rename from custom_components/tesla/translations/lb.json rename to custom_components/tesla_custom/translations/lb.json diff --git a/custom_components/tesla/translations/lv.json b/custom_components/tesla_custom/translations/lv.json similarity index 100% rename from custom_components/tesla/translations/lv.json rename to custom_components/tesla_custom/translations/lv.json diff --git a/custom_components/tesla/translations/nl.json b/custom_components/tesla_custom/translations/nl.json similarity index 100% rename from custom_components/tesla/translations/nl.json rename to custom_components/tesla_custom/translations/nl.json diff --git a/custom_components/tesla/translations/no.json b/custom_components/tesla_custom/translations/no.json similarity index 100% rename from custom_components/tesla/translations/no.json rename to custom_components/tesla_custom/translations/no.json diff --git a/custom_components/tesla/translations/pl.json b/custom_components/tesla_custom/translations/pl.json similarity index 100% rename from custom_components/tesla/translations/pl.json rename to custom_components/tesla_custom/translations/pl.json diff --git a/custom_components/tesla/translations/pt-BR.json b/custom_components/tesla_custom/translations/pt-BR.json similarity index 100% rename from custom_components/tesla/translations/pt-BR.json rename to custom_components/tesla_custom/translations/pt-BR.json diff --git a/custom_components/tesla/translations/pt.json b/custom_components/tesla_custom/translations/pt.json similarity index 100% rename from custom_components/tesla/translations/pt.json rename to custom_components/tesla_custom/translations/pt.json diff --git a/custom_components/tesla/translations/ru.json b/custom_components/tesla_custom/translations/ru.json similarity index 100% rename from custom_components/tesla/translations/ru.json rename to custom_components/tesla_custom/translations/ru.json diff --git a/custom_components/tesla/translations/sl.json b/custom_components/tesla_custom/translations/sl.json similarity index 100% rename from custom_components/tesla/translations/sl.json rename to custom_components/tesla_custom/translations/sl.json diff --git a/custom_components/tesla/translations/sv.json b/custom_components/tesla_custom/translations/sv.json similarity index 100% rename from custom_components/tesla/translations/sv.json rename to custom_components/tesla_custom/translations/sv.json diff --git a/custom_components/tesla/translations/tr.json b/custom_components/tesla_custom/translations/tr.json similarity index 100% rename from custom_components/tesla/translations/tr.json rename to custom_components/tesla_custom/translations/tr.json diff --git a/custom_components/tesla/translations/uk.json b/custom_components/tesla_custom/translations/uk.json similarity index 100% rename from custom_components/tesla/translations/uk.json rename to custom_components/tesla_custom/translations/uk.json diff --git a/custom_components/tesla/translations/zh-Hant.json b/custom_components/tesla_custom/translations/zh-Hant.json similarity index 100% rename from custom_components/tesla/translations/zh-Hant.json rename to custom_components/tesla_custom/translations/zh-Hant.json diff --git a/pyproject.toml b/pyproject.toml index 3d3de8fb..6d143c38 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,7 @@ teslajsonpy = "^0.17.1" [tool.poetry.dev-dependencies] homeassistant = "^2021.3.4" -pytest-homeassistant-custom-component = "0.1.0" +pytest-homeassistant-custom-component = "~0.3.0" bandit = "^1.7.0" black = {version = "^20.8b1", allow-prereleases = true} mypy = "^0.812" @@ -24,8 +24,8 @@ requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" [tool.semantic_release] -version_variable='pyproject.toml:version,custom_components/tesla/const.py:VERSION' -version_pattern='custom_components/tesla/manifest.json:"version": "{version}"' +version_variable='pyproject.toml:version,custom_components/tesla_custom/const.py:VERSION' +version_pattern='custom_components/tesla_custom/manifest.json:"version": "{version}"' upload_to_pypi=false upload_to_release=false changelog_sections="feature,fix,breaking,documentation,performance,refactor" diff --git a/setup.cfg b/setup.cfg index e1e328cc..d68a1bc4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -23,4 +23,3 @@ ignore_missing_imports = true warn_incomplete_stub = true warn_redundant_casts = true warn_unused_configs = true -exclude=custom_components\/(?!tesla).* diff --git a/tests/__init__.py b/tests/__init__.py index 35d25f27..48a22e51 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1 +1 @@ -"""Tests for Home Assistant.""" +"""Tests for Tesla Custom Integration.""" diff --git a/tests/test_config_flow.py b/tests/test_config_flow.py index 25d0fe8c..389fd118 100644 --- a/tests/test_config_flow.py +++ b/tests/test_config_flow.py @@ -22,12 +22,12 @@ import voluptuous as vol from yarl import URL -from custom_components.tesla.config_flow import ( +from custom_components.tesla_custom.config_flow import ( TeslaAuthorizationCallbackView, TeslaAuthorizationProxyView, validate_input, ) -from custom_components.tesla.const import ( +from custom_components.tesla_custom.const import ( AUTH_CALLBACK_PATH, AUTH_PROXY_PATH, CONF_EXPIRATION, @@ -48,7 +48,7 @@ # pytestmark = pytest.mark.skip(reason="unable to override core component") -@pytest.mark.skip(reason="unable to override core component") +# @pytest.mark.skip(reason="unable to override core component") async def test_warning_form(hass): """Test we get the warning form.""" result = await hass.config_entries.flow.async_init( @@ -71,7 +71,7 @@ async def test_warning_form(hass): return result -@pytest.mark.skip(reason="unable to override core component") +# @pytest.mark.skip(reason="unable to override core component") async def test_reauth_warning_form(hass): """Test we get the warning form on reauth.""" result = await hass.config_entries.flow.async_init( @@ -94,13 +94,13 @@ async def test_reauth_warning_form(hass): return result -@pytest.mark.skip(reason="unable to override core component") +@pytest.mark.skip(reason="hass fixture does not support http views") async def test_external_url(hass): """Test we get the external url after submitting once.""" result = await test_warning_form(hass) flow_id = result["flow_id"] with patch( - "custom_components.tesla.config_flow.get_url", + "custom_components.tesla_custom.config_flow.get_url", return_value=HA_URL, ): result = await hass.config_entries.flow.async_configure( @@ -129,13 +129,13 @@ async def test_external_url(hass): return result -@pytest.mark.skip(reason="unable to override core component") +# @pytest.mark.skip(reason="unable to override core component") async def test_external_url_no_hass_url_exception(hass): """Test we handle case with no detectable hass external url.""" result = await test_warning_form(hass) flow_id = result["flow_id"] with patch( - "custom_components.tesla.config_flow.get_url", + "custom_components.tesla_custom.config_flow.get_url", side_effect=NoURLAvailableError, ): result = await hass.config_entries.flow.async_configure( @@ -156,7 +156,7 @@ async def test_external_url_no_hass_url_exception(hass): assert result["description_placeholders"] == {} -@pytest.mark.skip(reason="unable to override core component") +@pytest.mark.skip(reason="hass fixture does not support http views") async def test_external_url_callback(hass): """Test we get the processing of callback_url.""" result = await test_external_url(hass) @@ -181,13 +181,13 @@ async def test_external_url_callback(hass): return result -@pytest.mark.skip(reason="unable to override core component") +@pytest.mark.skip(reason="hass fixture does not support http views") async def test_finish_oauth(hass): """Test config entry after finishing oauth.""" result = await test_external_url_callback(hass) flow_id = result["flow_id"] with patch( - "custom_components.tesla.config_flow.TeslaAPI.connect", + "custom_components.tesla_custom.config_flow.TeslaAPI.connect", return_value={ "refresh_token": TEST_TOKEN, CONF_ACCESS_TOKEN: TEST_ACCESS_TOKEN, @@ -221,13 +221,13 @@ async def test_finish_oauth(hass): return result -@pytest.mark.skip(reason="unable to override core component") +@pytest.mark.skip(reason="hass fixture does not support http views") async def test_form_invalid_auth(hass): """Test we handle invalid auth error.""" result = await test_external_url_callback(hass) flow_id = result["flow_id"] with patch( - "custom_components.tesla.config_flow.TeslaAPI.connect", + "custom_components.tesla_custom.config_flow.TeslaAPI.connect", side_effect=TeslaException(code=HTTP_UNAUTHORIZED), ): result = await hass.config_entries.flow.async_configure( @@ -246,13 +246,13 @@ async def test_form_invalid_auth(hass): assert result["description_placeholders"] is None -@pytest.mark.skip(reason="unable to override core component") +@pytest.mark.skip(reason="hass fixture does not support http views") async def test_form_login_failed(hass): """Test we handle invalid auth error.""" result = await test_external_url_callback(hass) flow_id = result["flow_id"] with patch( - "custom_components.tesla.config_flow.TeslaAPI.connect", + "custom_components.tesla_custom.config_flow.TeslaAPI.connect", return_value={}, ): result = await hass.config_entries.flow.async_configure( @@ -271,13 +271,13 @@ async def test_form_login_failed(hass): assert result["description_placeholders"] is None -@pytest.mark.skip(reason="unable to override core component") +@pytest.mark.skip(reason="hass fixture does not support http views") async def test_form_cannot_connect(hass): """Test we handle cannot connect error.""" result = await test_external_url_callback(hass) flow_id = result["flow_id"] with patch( - "custom_components.tesla.config_flow.TeslaAPI.connect", + "custom_components.tesla_custom.config_flow.TeslaAPI.connect", side_effect=TeslaException(code=HTTP_NOT_FOUND), ): result = await hass.config_entries.flow.async_configure( @@ -296,7 +296,7 @@ async def test_form_cannot_connect(hass): assert result["description_placeholders"] is None -@pytest.mark.skip(reason="unable to override core component") +@pytest.mark.skip(reason="hass fixture does not support http views") async def test_form_repeat_identifier(hass): """Test we handle repeat identifiers. @@ -318,7 +318,7 @@ async def test_form_repeat_identifier(hass): result = await test_external_url_callback(hass) flow_id = result["flow_id"] with patch( - "custom_components.tesla.config_flow.TeslaAPI.connect", + "custom_components.tesla_custom.config_flow.TeslaAPI.connect", return_value={ "refresh_token": TEST_TOKEN, CONF_ACCESS_TOKEN: TEST_ACCESS_TOKEN, @@ -341,7 +341,7 @@ async def test_form_repeat_identifier(hass): assert result["description_placeholders"] is None -@pytest.mark.skip(reason="unable to override core component") +@pytest.mark.skip(reason="hass fixture does not support http views") async def test_form_second_identifier(hass): """Test we can create another entry with a different name. @@ -363,7 +363,7 @@ async def test_form_second_identifier(hass): assert len(hass.config_entries.async_entries(DOMAIN)) == 2 -@pytest.mark.skip(reason="unable to override core component") +@pytest.mark.skip(reason="hass fixture does not support http views") async def test_form_reauth(hass): """Test we handle reauth.""" entry = MockConfigEntry( @@ -381,7 +381,7 @@ async def test_form_reauth(hass): result = await test_external_url_callback(hass) flow_id = result["flow_id"] with patch( - "custom_components.tesla.config_flow.TeslaAPI.connect", + "custom_components.tesla_custom.config_flow.TeslaAPI.connect", return_value={ "refresh_token": TEST_TOKEN, CONF_ACCESS_TOKEN: TEST_ACCESS_TOKEN, @@ -408,7 +408,7 @@ async def test_form_reauth(hass): assert result["description_placeholders"] is None -@pytest.mark.skip(reason="unable to override core component") +# @pytest.mark.skip(reason="unable to override core component") async def test_import(hass): """Test import step results in warning form.""" result = await hass.config_entries.flow.async_init( @@ -516,7 +516,9 @@ async def test_callback_view_invalid_query(hass, aiohttp_client, callback_view): resp = await client.get(AUTH_CALLBACK_PATH, params={"flow_id": 1234}) assert resp.status == 400 - with patch("custom_components.tesla.async_setup_entry", side_effect=KeyError): + with patch( + "custom_components.tesla_custom.async_setup_entry", side_effect=KeyError + ): resp = await client.get(AUTH_CALLBACK_PATH, params={"flow_id": 1234}) assert resp.status == 400 @@ -526,7 +528,9 @@ async def test_callback_view_keyerror(hass, aiohttp_client, callback_view): """Test callback view with keyerror.""" client = await aiohttp_client(hass.http.app) - with patch("custom_components.tesla.async_setup_entry", side_effect=KeyError): + with patch( + "custom_components.tesla_custom.async_setup_entry", side_effect=KeyError + ): resp = await client.get(AUTH_CALLBACK_PATH, params={"flow_id": 1234}) assert resp.status == 400 @@ -536,7 +540,9 @@ async def test_callback_view_unknownflow(hass, aiohttp_client, callback_view): """Test callback view with unknownflow.""" client = await aiohttp_client(hass.http.app) - with patch("custom_components.tesla.async_setup_entry", side_effect=UnknownFlow): + with patch( + "custom_components.tesla_custom.async_setup_entry", side_effect=UnknownFlow + ): resp = await client.get(AUTH_CALLBACK_PATH, params={"flow_id": 1234}) assert resp.status == 400 @@ -549,7 +555,7 @@ async def test_callback_view_success(hass, aiohttp_client, callback_view): client = await aiohttp_client(hass.http.app) - with patch("custom_components.tesla.async_setup_entry", return_value=True): + with patch("custom_components.tesla_custom.async_setup_entry", return_value=True): resp = await client.get(AUTH_CALLBACK_PATH, params={"flow_id": flow_id}) assert resp.status == 200 assert ( @@ -712,7 +718,7 @@ async def test_validate_input_no_controller( CONF_EXPIRATION: TEST_VALID_EXPIRATION, } with patch( - "custom_components.tesla.config_flow.TeslaAPI.connect", + "custom_components.tesla_custom.config_flow.TeslaAPI.connect", return_value={ "refresh_token": TEST_TOKEN, CONF_ACCESS_TOKEN: TEST_ACCESS_TOKEN, diff --git a/tests/test_tesla_device.py b/tests/test_tesla_device.py index 8df985ec..9d2041d4 100644 --- a/tests/test_tesla_device.py +++ b/tests/test_tesla_device.py @@ -4,7 +4,8 @@ import pytest from teslajsonpy.exceptions import IncompleteCredentials -from custom_components.tesla.tesla_device import TeslaDevice +from custom_components.tesla_custom.const import DOMAIN +from custom_components.tesla_custom.tesla_device import TeslaDevice @pytest.fixture @@ -63,7 +64,7 @@ def test_tesla_init(tesla_device_mock): assert tesla_device_mock.unique_id == "uniq_id" assert tesla_device_mock.icon == "mdi:battery" assert tesla_device_mock.device_info == { - "identifiers": {("tesla", 1)}, + "identifiers": {(DOMAIN, 1)}, "manufacturer": "Tesla", "model": "car_type", "name": "car_name", @@ -105,7 +106,7 @@ def test_tesla_inherited_init(tesla_inherited_mock): assert tesla_inherited_mock.unique_id == "uniq_id" assert tesla_inherited_mock.icon == "mdi:battery" assert tesla_inherited_mock.device_info == { - "identifiers": {("tesla", 1)}, + "identifiers": {(DOMAIN, 1)}, "manufacturer": "Tesla", "model": "car_type", "name": "car_name",