Python IDE autocomplete missing some methods from AppDaemon plugin class
Question:
I’m trying to use autocomplete for the Hass
class from the Python AppDaemon package. Autocomplete is showing some of the inherited methods from the superclass such as get_state()
, but some methods are missing, such as log()
and get_entity()
. This behavior is the same in VS Code and PyCharm Community.
Here’s the skeleton of a class I’m writing, which inherits from hass.Hass
:
import hassapi as hass
class AutocompleteTest(hass.Hass):
def initialize(self):
self.get
Here’s the class it inherits from (GitHub link):
class Hass(adbase.ADBase, adapi.ADAPI):
The methods I want to autocomplete are in the superclass adapi.ADAPI
(GitHub link). Here are the method definitions from that class:
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:
Can anyone help me understand what’s going on, and how to get autocomplete fully working?
My requirements file:
hassapi
iso8601
requests
Answers:
I used a very small example to try to reproduce the problem, but I can get intelligent.
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.
If you use this example, can you get intelligent prompt?
The hassapi
package on PyPI (hass-api/hassapi) and your requirements file is unaffiliated with AppDaemon.
At runtime, AppDaemon does sys.path.insert(0, plugin)
for its own hass
plugin (AppDaemon/appdaemon/…/appdaemon/plugins/hass) containing the hassapi
module.
To get autocomplete, install appdaemon
package instead.
- Either change your import statement to directly import AppDaemon’s
hassapi
module:
# import hassapi as hass
from appdaemon.plugins.hass import hassapi as hass
- Or create a file
hassapi.py
in the same directory as autocomplete-test.py containing:
from appdaemon.plugins.hass.hassapi import *
I’m trying to use autocomplete for the Hass
class from the Python AppDaemon package. Autocomplete is showing some of the inherited methods from the superclass such as get_state()
, but some methods are missing, such as log()
and get_entity()
. This behavior is the same in VS Code and PyCharm Community.
Here’s the skeleton of a class I’m writing, which inherits from hass.Hass
:
import hassapi as hass
class AutocompleteTest(hass.Hass):
def initialize(self):
self.get
Here’s the class it inherits from (GitHub link):
class Hass(adbase.ADBase, adapi.ADAPI):
The methods I want to autocomplete are in the superclass adapi.ADAPI
(GitHub link). Here are the method definitions from that class:
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:
Can anyone help me understand what’s going on, and how to get autocomplete fully working?
My requirements file:
hassapi
iso8601
requests
I used a very small example to try to reproduce the problem, but I can get intelligent.
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.
If you use this example, can you get intelligent prompt?
The hassapi
package on PyPI (hass-api/hassapi) and your requirements file is unaffiliated with AppDaemon.
At runtime, AppDaemon does sys.path.insert(0, plugin)
for its own hass
plugin (AppDaemon/appdaemon/…/appdaemon/plugins/hass) containing the hassapi
module.
To get autocomplete, install appdaemon
package instead.
- Either change your import statement to directly import AppDaemon’s
hassapi
module:
# import hassapi as hass
from appdaemon.plugins.hass import hassapi as hass
- Or create a file
hassapi.py
in the same directory as autocomplete-test.py containing:
from appdaemon.plugins.hass.hassapi import *