TECH7Fox / asterisk-hass-integration

Asterisk integration for Home Assistant
57 stars 13 forks source link

Add SCCP and IAX Channels #97

Open cbailes78 opened 4 months ago

cbailes78 commented 4 months ago

Hi Jordy,

Thank you for your excellent work on asterisk-hass-integration.

I have added SCCP and IAX channels to your excellent custom component. Please would you consider merging my pull request to help others.

Many thanks.

All best, Chris.

cbailes78 commented 4 months ago

Hi Jordy,

I had to gate the adding of the interfaces because SIP and IAX have identical end-of-list responses (event.name == "PeerlistComplete"). Without this, it would try to add all IAPX interfaces as both SIP/nnn and IAX/nnn. HA would recognise it had already been configured and stop the addition of the IAX/nnn as duplicates. Net result wase the IAX channels appeared as SIP.

Great work on the custom integration, it works like a charm.

All best, Chris

On Wed, Feb 21, 2024 at 1:40 AM Jordy Kuhne @.***> wrote:

@.**** commented on this pull request.

In custom_components/asterisk/init.py https://github.com/TECH7Fox/asterisk-hass-integration/pull/97#discussion_r1496759900 :

 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":

Why did you add the sip_loaded == False here?

— Reply to this email directly, view it on GitHub https://github.com/TECH7Fox/asterisk-hass-integration/pull/97#pullrequestreview-1891886836, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJAPNAIDKQGSORZV2ZZOWEDYUVGBBAVCNFSM6AAAAABDOKOPTWVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTQOJRHA4DMOBTGY . You are receiving this because you authored the thread.Message ID: @.***>

TECH7Fox commented 4 months ago

Hi @cbailes78,

Thank you for the PR! I don't think that IAX and SCCP devices have events for some entities like the DTMF or Connected Line entity, so those entities would do nothing. Maybe have a check like here and here and only add certain entities if the device tech type actually has those events. And the same could be done for events that only IAX or SCCP devices have. (not sure if there are any though, can't quickly find anything in the docs)

So for example something like:

# in sensor.py / binary_sensor.py
for device in devices:
  entities.append(DeviceStateSensor(hass, entry, device))
  if device.tech == "SIP" or device.tech == "PJSIP":
    entities.append(ConnectedLineSensor(hass, entry, device))
    entities.append(DTMFSentSensor(hass, entry, device))
    entities.append(DTMFReceivedSensor(hass, entry, device))

Just a example.