Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SCCP and IAX Channels #97

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 49 additions & 9 deletions custom_components/asterisk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady

from .const import AUTO_RECONNECT, CLIENT, DOMAIN, PLATFORMS, SIP_LOADED, PJSIP_LOADED
from .const import AUTO_RECONNECT, CLIENT, DOMAIN, PLATFORMS, SIP_LOADED, PJSIP_LOADED, SCCP_LOADED, IAX_LOADED

_LOGGER = logging.getLogger(__name__)

Expand All @@ -39,20 +39,44 @@ def create_SIP_device(event: Event, **kwargs):
}
hass.data[DOMAIN][entry.entry_id][CONF_DEVICES].append(device)

def create_SCCP_device(event: Event, **kwargs):
_LOGGER.debug("Creating SCCP device: %s", event)
device = {
"extension": event["Name"],
"tech": "SCCP",
"status": event["ObjectType"],
}
hass.data[DOMAIN][entry.entry_id][CONF_DEVICES].append(device)

def create_IAX_device(event: Event, **kwargs):
_LOGGER.debug("Creating IAX device: %s", event)
device = {
"extension": event["ObjectName"],
"tech": "IAX",
"status": event["Status"],
}
hass.data[DOMAIN][entry.entry_id][CONF_DEVICES].append(device)

def devices_complete(event: Event, **kwargs):
sip_loaded = hass.data[DOMAIN][entry.entry_id][SIP_LOADED]
pjsip_loaded = hass.data[DOMAIN][entry.entry_id][PJSIP_LOADED]
if event.name == "PeerlistComplete":
sccp_loaded = hass.data[DOMAIN][entry.entry_id][SCCP_LOADED]
iax_loaded = hass.data[DOMAIN][entry.entry_id][IAX_LOADED]
if sip_loaded == False and event.name == "PeerlistComplete":
TECH7Fox marked this conversation as resolved.
Show resolved Hide resolved
_LOGGER.debug("SIP loaded.")
sip_loaded = True
hass.data[DOMAIN][entry.entry_id][SIP_LOADED] = True
elif event.name == "EndpointListComplete":
elif pjsip_loaded == False and event.name == "EndpointListComplete":
_LOGGER.debug("PJSIP loaded.")
pjsip_loaded = True
hass.data[DOMAIN][entry.entry_id][PJSIP_LOADED] = True

if sip_loaded and pjsip_loaded:
_LOGGER.debug("Both SIP and PJSIP loaded. Loading platforms.")
elif sccp_loaded == False and event.name == "SCCPListLinesComplete":
_LOGGER.debug("SCCP loaded.")
hass.data[DOMAIN][entry.entry_id][SCCP_LOADED] = True
elif iax_loaded == False and event.name == "PeerlistComplete":
_LOGGER.debug("IAX loaded.")
hass.data[DOMAIN][entry.entry_id][IAX_LOADED] = True

if sip_loaded and pjsip_loaded and sccp_loaded and iax_loaded:
_LOGGER.debug("SIP, PJSIP, SCCP and IAX loaded. Loading platforms.")
for component in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, component)
Expand Down Expand Up @@ -95,10 +119,12 @@ async def send_action_service(call) -> None:
CONF_DEVICES: [],
SIP_LOADED: False,
PJSIP_LOADED: False,
SCCP_LOADED: False,
IAX_LOADED: False,
}
hass.services.async_register(DOMAIN, "send_action", send_action_service)

client.add_event_listener(create_SIP_device, white_list=["PeerEntry"])
client.add_event_listener(create_SIP_device, white_list=["PeerEntry"], Channeltype='SIP')
client.add_event_listener(devices_complete, white_list=["PeerlistComplete"])
f = client.send_action(SimpleAction("SIPpeers"))
if f.response.is_error():
Expand All @@ -112,6 +138,20 @@ async def send_action_service(call) -> None:
_LOGGER.debug("PJSIP module not loaded. Skipping PJSIP devices.")
hass.data[DOMAIN][entry.entry_id][PJSIP_LOADED] = True

client.add_event_listener(create_SCCP_device, white_list=["LineEntry"])
client.add_event_listener(devices_complete, white_list=["SCCPListLinesComplete"])
f = client.send_action(SimpleAction("SCCPListLines"))
if f.response.is_error():
_LOGGER.debug("SCCP module not loaded. Skipping SCCP devices.")
hass.data[DOMAIN][entry.entry_id][SCCP_LOADED] = True

client.add_event_listener(create_IAX_device, white_list=["PeerEntry"], Channeltype='IAX')
client.add_event_listener(devices_complete, white_list=["PeerlistComplete"])
f = client.send_action(SimpleAction("IAXpeerList"))
if f.response.is_error():
_LOGGER.debug("IAX module not loaded. Skipping IAX devices.")
hass.data[DOMAIN][entry.entry_id][IAX_LOADED] = True

return True


Expand Down
4 changes: 3 additions & 1 deletion custom_components/asterisk/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@
"Unknown": "mdi:phone-off",
}
SIP_LOADED = "sip_loaded"
PJSIP_LOADED = "pjsip_loaded"
PJSIP_LOADED = "pjsip_loaded"
SCCP_LOADED = "sccp_loaded"
IAX_LOADED = "iax_loaded"
Loading