Repository: home-assistant-ecosystem/home-assistant-cli (language: python)

Issue:
info command uses deprecated discovery_info API endpoint
When running the `hass-cli info` command it fails with the error `error: HTTPError: 404 Client Error: Not Found for url: http://192.168.178.123:8123/api/discovery_info`

The `discovery_info` endpoint has been deprecated (see https://www.home-assistant.io/blog/2021/10/06/release-202110/#breaking-changes Discvery API section) and removed in 2022.2.


Discussion / hints:
Thanks for sharing, I was wondering why it wasn't working!
I did a little digging and here's some info on what should be use as an alternative (from Paulus himself):

https://community.home-assistant.io/t/2021-10-0-z-wave-s2-support-tuya-secure-esphome-and-400-new-icons/344457/59
`discovery_info` basically gathered the details which are used to announce the presence of a Home Assistant instance in the local network (mDNS).

Looks like that `hass-cli info` command could be removed now.

Fix patch:
diff --git a/homeassistant_cli/plugins/info.py b/homeassistant_cli/plugins/info.py
deleted file mode 100644
index 2548baf..0000000
--- a/homeassistant_cli/plugins/info.py
+++ /dev/null
@@ -1,31 +0,0 @@
-"""Info plugin for Home Assistant CLI (hass-cli)."""
-import logging
-
-import click
-
-from homeassistant_cli.cli import pass_context
-from homeassistant_cli.config import Configuration
-from homeassistant_cli.helper import format_output
-import homeassistant_cli.remote as api
-
-_LOGGING = logging.getLogger(__name__)
-
-
-@click.command('info')
-@pass_context
-def cli(ctx: Configuration):
-    """Get basic info from Home Assistant."""
-    ctx.auto_output("table")
-    cols = [
-        ("BASE_URL", "base_url"),
-        ("LOCATION", "location_name"),
-        ("REQUIRES_API_PASSWORD", "requires_api_password"),
-        ("VERSION", "version"),
-    ]
-    ctx.echo(
-        format_output(
-            ctx,
-            [api.get_info(ctx)],
-            columns=ctx.columns if ctx.columns else cols,
-        )
-    )


Test patch:
diff --git a/tests/test_defaults.py b/tests/test_defaults.py
index 97d64e6..db4038e 100644
--- a/tests/test_defaults.py
+++ b/tests/test_defaults.py
@@ -75,13 +75,13 @@ def test_defaults(
     try:
         mockenv.start()
         with requests_mock.mock() as mockhttp:
-            expserver = "{}/api/discovery_info".format(
-                expected_resolved_server
-            )
+            expserver = f"{expected_resolved_server}/api/config"
             mockhttp.get(
                 expserver, json={"name": "mock response"}, status_code=200
             )
-            ctx = cli.cli.make_context('hass-cli', ['--timeout', '1', 'info'])
+            ctx = cli.cli.make_context(
+                'hass-cli', ['--timeout', '1', 'config']
+            )
             with ctx:  # type: ignore
                 cli.cli.invoke(ctx)
 
diff --git a/tests/test_info.py b/tests/test_info.py
deleted file mode 100644
index e46506a..0000000
--- a/tests/test_info.py
+++ /dev/null
@@ -1,88 +0,0 @@
-"""Tests file for Home Assistant CLI (hass-cli)."""
-import json
-from typing import Any
-
-from click.testing import CliRunner
-import requests_mock
-
-import homeassistant_cli.cli as cli
-from homeassistant_cli.exceptions import HomeAssistantCliError
-import homeassistant_cli.yaml as yaml
-
-VALID_INFO = {
-    "base_url": "http://192.168.1.156:8123",
-    "location_name": "Home",
-    "requires_api_password": "false",
-    "version": "0.82.1",
-}
-
-
-def ordered(obj: Any):
-    """Sort object recursively. Useful for comparing JSON/YAML dicts."""
-    if isinstance(obj, dict):
-        return sorted((k, ordered(v)) for k, v in obj.items())
-    if isinstance(obj, list):
-        return sorted(ordered(x) for x in obj)
-
-    return obj
-
-
-def test_info_without_server_running() -> None:
-    """Test proper failure when server not running."""
-    runner = CliRunner()
-    result = runner.invoke(
-        cli.cli, ['--server', 'http://donotexist.inf', 'info']
-    )
-    assert result.exit_code == 1
-    assert isinstance(result.exception, HomeAssistantCliError)
-    assert str(result.exception) == "Unexpected error retrieving information"
-
-
-def test_info_json() -> None:
-    """Test info reads properly with JSON."""
-    with requests_mock.Mocker() as mock:
-        mock.get(
-            'http://localhost:8123/api/discovery_info',
-            json=VALID_INFO,
-            status_code=200,
-        )
-
-        runner = CliRunner()
-        result = runner.invoke(
-            cli.cli, ['--output=json', 'info'], catch_exceptions=False
-        )
-        assert result.exit_code == 0
-        assert [VALID_INFO] == json.loads(result.output)
-
-
-def test_info_unauth() -> None:
-    """Test info reads properly with JSON."""
-    with requests_mock.Mocker() as mock:
-        mock.get(
-            'http://localhost:8123/api/discovery_info',
-            json={},
-            status_code=401,
-        )
-
-        runner = CliRunner()
-        result = runner.invoke(
-            cli.cli, ['--output=json', 'info'], catch_exceptions=True
-        )
-        assert result.exit_code != 0
-
-
-def test_info_yaml() -> None:
-    """Test info reads properly with YAML."""
-    with requests_mock.Mocker() as mock:
-        mock.get(
-            'http://localhost:8123/api/discovery_info',
-            json=VALID_INFO,
-            status_code=200,
-        )
-
-        runner = CliRunner()
-        result = runner.invoke(
-            cli.cli, ['--output=yaml', 'info'], catch_exceptions=False
-        )
-        assert result.exit_code == 0
-        assert [VALID_INFO] == yaml.loadyaml(yaml.yaml(), result.output)