Python IDE自动完成缺少AppDaemon插件类的某些方法

ac1kyiln  于 2023-01-24  发布在  Python
关注(0)|答案(2)|浏览(195)

我尝试对Python AppDaemon包中的Hass类使用autocomplete。Autocomplete显示了一些从超类继承的方法,比如get_state(),但是缺少一些方法,比如log()get_entity()。这个行为在VS Code和PyCharm社区中是相同的。

下面是我正在编写的一个类的框架,它继承自hass.Hass

import hassapi as hass

class AutocompleteTest(hass.Hass):

    def initialize(self):
        self.get

下面是它从(GitHub link)继承的类:

class Hass(adbase.ADBase, adapi.ADAPI):

我想自动完成的方法在超类adapi.ADAPIGitHub link)中,下面是这个类的方法定义:

class ADAPI:
  # This method shows in autocomplete
  @utils.sync_wrapper
  async def get_state(
    self,
    entity_id: str = None,
    attribute: str = None,
    default: Any = None,
    copy: bool = True,
    **kwargs: Optional[Any],
  ) -> Any:

  # This method does not show in autocomplete
  def log(self, msg, *args, **kwargs):

  # This method does not show in autocomplete
  def get_entity(self, entity: str, **kwargs: Optional[Any]) -> Entity:

有人能帮我理解这是怎么回事,以及如何让自动完成完全工作吗?
我的需求文件:

hassapi
iso8601
requests
v8wbuo2f

v8wbuo2f1#

PyPI(hass-api/hassapi)上的hassapi包和您的需求文件与AppDaemon无关。
在运行时,AppDaemon会为自己的hass插件(AppDaemon/appdaemon/.../appdaemon/plugins/hass)执行sys.path.insert(0, plugin),该插件包含hassapi模块。
要获得自动完成,请安装appdaemon包。
1.更改import语句以直接导入AppDaemon的hassapi模块:

# import hassapi as hass
from appdaemon.plugins.hass import hassapi as hass

1.或者在与www.example.com相同的目录中创建一个文件hassapi.pyautocomplete-test.py包含:

from appdaemon.plugins.hass.hassapi import *
js81xvg6

js81xvg62#

我用了一个很小的例子来重现这个问题,但我可以变得聪明。
test1.py:

class ADAPI:
    def get_entity(self, entity: str, **kwargs: Optional[Any]) -> Entity:
        namespace = self._get_namespace(**kwargs)
        self._check_entity(namespace, entity)
        entity_id = Entity(self.logger, self.AD, self.name, namespace, entity)

        return entity_id

test2.py

import test1 as adapi

class Hass(adbase.ADBase, adapi.ADAPI):
      def __init__(self, ad: AppDaemon, name, logging, args, config, app_config, global_vars):
        adapi.ADAPI.__init__(self, ad, name, logging, args, config, app_config, global_vars)

test3.py:

import test2 as hass
class AutocompleteTest(hass.Hass):
  def initialize(self):
    self.

如果你使用这个例子,你能得到智能提示吗?

相关问题