Hi,
I used to have a custom component that used the home assistant API to parse my entities states and return the state of a single entity via a local URL.
So for example
this query -> https://myinstance:8123/textapi/state/entity_id?api_password:xxxxxxxxx would return the state value of the entity (e.g On, Off, etc)
It used to work perfectly on my version 0.75 hassio.
However now that I have it updated to the 0.82 version it doesn’t work anymore and my custom component fails to load.
Here’s my log errors :
2018-11-27 17:58:00 ERROR (MainThread) [homeassistant.loader] Error loading custom_components.textapi. Make sure all dependencies are installed
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/homeassistant/loader.py", line 92, in get_component
module = importlib.import_module(path)
File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/config/custom_components/textapi.py", line 14, in <module>
import homeassistant.remote as rem
ModuleNotFoundError: No module named 'homeassistant.remote'
2018-11-27 17:58:00 ERROR (MainThread) [homeassistant.loader] Unable to find component textapi
2018-11-27 17:58:00 ERROR (MainThread) [homeassistant.setup] Setup failed for textapi: Component not found.
I read somewhere that it may be because the homeassistante.remote module is not supported anymore.
So does anyone know any workaround ? Thanks
Here’s my custom component python script (feel free to use it if it’s useful for someone)
import asyncio
import json
import logging
from aiohttp import web
import async_timeout
import homeassistant.core as ha
import homeassistant.remote as rem
from homeassistant.bootstrap import DATA_LOGGING
from homeassistant.const import (
EVENT_HOMEASSISTANT_STOP, EVENT_TIME_CHANGED,
HTTP_BAD_REQUEST, HTTP_CREATED, HTTP_NOT_FOUND,
MATCH_ALL, URL_API, URL_API_COMPONENTS,
URL_API_CONFIG, URL_API_DISCOVERY_INFO, URL_API_ERROR_LOG,
URL_API_EVENTS, URL_API_SERVICES,
URL_API_STATES, URL_API_STATES_ENTITY, URL_API_STREAM, URL_API_TEMPLATE,
__version__)
from homeassistant.exceptions import TemplateError
from homeassistant.helpers.state import AsyncTrackStates
from homeassistant.helpers import template
from homeassistant.components.http import HomeAssistantView
DOMAIN = 'textapi'
def setup(hass, config):
hass.states.set('textapi.world', 'Vince')
"""Register the API with the HTTP interface."""
hass.http.register_view(TextAPIStatusView)
hass.http.register_view(TextAPIEntityStateView)
return True
class TextAPIStatusView(HomeAssistantView):
"""View to handle Status requests."""
url = '/textapi/'
name = "textapi:status"
@ha.callback
def get(self, request):
"""Retrieve if API is running."""
return web.Response(text="Hello, api text world !")
class TextAPIEntityStateView(HomeAssistantView):
"""View to handle EntityState requests."""
url = "/textapi/states/{entity_id}"
name = "textapi:entity-state"
@ha.callback
def get(self, request, entity_id):
"""Retrieve state of entity."""
state = request.app['hass'].states.get(entity_id)
if state:
return web.Response(text=state.state)
# return self.json(state)
# return self.json_message('Entity not found', HTTP_NOT_FOUND)
return web.HTTPNotFound(text="entity not found")
Thanks for your help