TECH7Fox / asterisk-hass-integration

Asterisk integration for Home Assistant
60 stars 14 forks source link

Consolidate NOT IN USE state #68

Closed felipecrs closed 1 year ago

felipecrs commented 1 year ago

image

TECH7Fox commented 1 year ago

Hmm. Weird. It is directly the state Asterisk gives.

felipecrs commented 1 year ago

So maybe this is an issue in the library the integration uses. I'll follow up.

felipecrs commented 1 year ago

Oh no. You are right. Most likely this is an issue in Asterisk itself. Sad.

felipecrs commented 1 year ago

Well... Reporting bugs in Asterisk is really complicated. It would be nice if we could do something like:

asterisk_state = event.get_header("State")
# Workaround for https://github.com/TECH7Fox/asterisk-hass-integration/issues/68
# Until the issue gets fixed upstream.
if asterisk_state == "NOT IN USE":
  self._state = "NOT_INUSE"
else:
  self._state = asterisk_state

I tried it but it doesn't seem to work. Anyway, if you think it's not a good idea, feel free to close this issue.

felipecrs commented 1 year ago

NOT IN USE only appears when the integration is first loaded/reload. Could this be because of this?

image

felipecrs commented 1 year ago

Yeah, this is actually how the issue is fixed for me:

def __init__(self, hass, status, extension, tech, entry):
        """Setting up extension."""
        self._hass = hass
        self._astmanager = hass.data[DOMAIN][entry.entry_id]["manager"]
        self._extension = extension
        self._state = "NOT_INUSE" if status == "NOT IN USE" else status
        self._tech = tech
        self._entry = entry
        self._unique_id = f"{entry.entry_id}_{extension}_state"
        self._astmanager.register_event("DeviceStateChange", self.handle_asterisk_event)

The question is, where do this "status" comes from?

TECH7Fox commented 1 year ago

Asterisk gives the state in a different format in some events then others, which is kinda weird but I've mapped them to be consistant now. Please reopen if you still get unexpected states.

felipecrs commented 1 year ago

Thanks a ton!