home-assistant-ecosystem / home-assistant-cli

:computer: Command-line tool for Home Assistant
Other
428 stars 64 forks source link

Fix completions #402

Open pschmitt opened 1 year ago

pschmitt commented 1 year ago

This fixes the following:

hass-cli service call <TAB>
'tuple' object has no attribute 'type'Traceback (most recent call last):
  File "/home/pschmitt/.local/share/zinit/plugins/home-assistant-ecosystem---home-assistant-cli/homeassistant_cli/cli.py", line 40, in run
    result = cli.main(standalone_mode=False)
  File "/home/pschmitt/.local/pipx/venvs/homeassistant-cli/lib/python3.10/site-packages/click/core.py", line 1050, in main
    self._main_shell_completion(extra, prog_name, complete_var)
  File "/home/pschmitt/.local/pipx/venvs/homeassistant-cli/lib/python3.10/site-packages/click/core.py", line 1125, in _main_shell_completion
    rv = shell_complete(self, ctx_args, prog_name, complete_var, instruction)
  File "/home/pschmitt/.local/pipx/venvs/homeassistant-cli/lib/python3.10/site-packages/click/shell_completion.py", line 49, in shell_complete
    echo(comp.complete())
  File "/home/pschmitt/.local/pipx/venvs/homeassistant-cli/lib/python3.10/site-packages/click/shell_completion.py", line 292, in complete
    out = [self.format_completion(item) for item in completions]
  File "/home/pschmitt/.local/pipx/venvs/homeassistant-cli/lib/python3.10/site-packages/click/shell_completion.py", line 292, in <listcomp>
    out = [self.format_completion(item) for item in completions]
  File "/home/pschmitt/.local/pipx/venvs/homeassistant-cli/lib/python3.10/site-packages/click/shell_completion.py", line 364, in format_completion
    return f"{item.type}\n{item.value}\n{item.help if item.help else '_'}

Click Completions should now return CompletionItem instances, instead of tuples.

Ref: https://github.com/pallets/click/blob/8.1.3/docs/shell-completion.rst#custom-type-completion

pschmitt commented 1 year ago

Have to admit that I can't figure out why the area completions test is failing 😐

EDIT: The area completion tests fail because get_areas() is a WS request that cannot be mocked by request_mock