Convert Twilio Component to SignalWire

What do I need to look at in order to take the Twilio code and duplicate it then update for SignalWire.

I can probably figure out what in the current Twilio code needs to be modified once I know all the pieces and how they interact with HA.

Is there someone will to help me with questions as I try this endeavor?

Currently I am running HA in a container so I am guessing that in my config directory, I would need to create a custom components directory to put my local work in.

What I am not sure about, is how to get the SignalWire python library usable for the container as it requires “pip install signalwire” for the hooks.

Any help is appreciated.

As I understand, code like REQUIREMENTS = ['PyMata==2.14'] (example from components\arduino_init_.py) in your custom component .py leads to execution pip install at hassio internal level.

Yep. You are correct. I did some additional digging in the development docs and found that out.

I started out trying to convert twilio, twilio_call, and twilio_sms. I am not sure the call feature is something I am interested in right now as there is a lot more work to do on that so I am going to focus on the sms only. Seems pretty straight forward.

Once I have it working, hopefully some folks can run it through the wringer for me and maybe get it merged in.

NM…

Need to pay more attention to the error.

Ok, definite issue here I cannot pinpoint.

Here is the config, the next to last line is the line is question

async def async_setup (hass, config):

""“Set up the SignalWire component.”""

from signalwire.rest import Client

if DOMAIN not in config:

return True

conf = config[DOMAIN]

hass.data[DATA_SIGNALWIRE] = Client(

conf.get(SIGNALWIRE_PROJECT_ID), conf.get(SIGNALWIRE_API_TOKEN), conf.get(SIGNALWIRE_SPACE_URL))

return True

And the error:

2019-04-12 18:22:17 ERROR (MainThread) [homeassistant.setup] Error during setup of component signalwire

File “/config/custom_components/ signalwire /init.py”, line 38, in async_setup

More info:

2019-04-12 18:52:01 ERROR (MainThread) [homeassistant.setup] Error during setup of component signalwire
Traceback (most recent call last):
File “/usr/local/lib/python3.7/site-packages/homeassistant/setup.py”, line 151, in _async_setup_component
hass, processed_config)
File “/config/custom_components/signalwire/init.py”, line 37, in async_setup
hass.data[DATA_SIGNALWIRE] = signalwire_client(conf.get(SIGNALWIRE_PROJECT_ID), conf.get(SIGNALWIRE_API_TOKEN), conf.get(SIGNALWIRE_SPACE_URL))
File “/config/deps/lib/python3.7/site-packages/signalwire/rest/init.py”, line 331, in init
signalwire_space_url = os.environ[‘SIGNALWIRE_SPACE_URL’]
File “/usr/local/lib/python3.7/os.py”, line 678, in getitem
raise KeyError(key) from None
KeyError: ‘SIGNALWIRE_SPACE_URL’

Figured it out.

I had this:
hass.data[DATA_TWILIO] = signalwire_client(
conf.get(CONF_ACCOUNT_SID), conf.get(CONF_AUTH_TOKEN), conf.get(CONF_SPACE_URL))

And it required this:

hass.data[DATA_TWILIO] = signalwire_client(
conf.get(CONF_ACCOUNT_SID), conf.get(CONF_AUTH_TOKEN), signalwire_space_url = conf.get(CONF_SPACE_URL))

Ok, next issue…

I created a signalwire_sms which depends on signalwire.

As you can see in the output, the signalwire component get installed but signalwire_sms cannot find it.

2019-04-12 20:24:24 WARNING (MainThread) [homeassistant.loader] You are using a custom component for signalwire which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.

2019-04-12 20:24:28 INFO (MainThread) [homeassistant.setup] Setting up signalwire

2019-04-12 20:24:28 INFO (MainThread) [homeassistant.setup] Setup of domain signalwire took 0.2 seconds.

2019-04-12 20:24:28 INFO (MainThread) [homeassistant.loader] Loaded signalwire _sms from custom_components. signalwire _sms

2019-04-12 20:24:28 WARNING (MainThread) [homeassistant.loader] You are using a custom component for signalwire _sms which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.

2019-04-12 20:24:28 ERROR (MainThread) [homeassistant.loader] Error loading custom_components. signalwire _sms.notify. Make sure all dependencies are installed

File “/config/custom_components/ signalwire _sms/notify.py”, line 6, in <module>

from homeassistant.components. signalwire import DATA_SIGNALWIRE

ModuleNotFoundError: No module named 'homeassistant.components. signalwire

2019-04-12 20:24:28 ERROR (MainThread) [homeassistant.loader] Unable to find platform signalwire _sms. Search path was limited to path of component: custom_components

Got it all working with custom components signalwire (converted from twilio) and signalwire_sms (converted from twilio_sms).

I have removed, for now, all of the web hook stuff from twilio nd have not yet attempted to convert twilio_call as that is probably a completed re write do to the Twilio webhook using the predefined Twimlets.