hass-agent / HASS.Agent

Unofficial development project for the HASS.Agent platform.
https://hass-agent.io
MIT License
314 stars 9 forks source link

New laptop doesn't allow me to send notifications / doesn't get discovered #127

Closed mhoogenbosch closed 2 months ago

mhoogenbosch commented 2 months ago

Describe the bug I have a new laptop. Old laptop works fine. Goal is to receive notifications. On my new laptop the test notification works fine. When API is enabled and I want to add it as HASSAgent integrtation i'm presented the following error:

Logger: homeassistant.config_entries
Bron: config_entries.py:586
Eerst voorgekomen: 09:16:17 (5 gebeurtenissen)
Laatst gelogd: 09:51:15

Error setting up entry DESKTOP-2Z5DV73-HassAgent for hass_agent
Error setting up entry G10LaptopHassAgent for hass_agent
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 586, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/hass_agent/__init__.py", line 135, in async_setup_entry
    _logger.debug("setting up device from config entry: %s [%s]", entry.data["device"]["name"], entry.unique_id)
                                                                  ~~~~~~~~~~^^^^^^^^^^
KeyError: 'device'

I don't need the API, but for some reason it doesn't get autodiscovered by my HA instance. My old laptop runs just fine. But laptops are HP laptops (different model), both are on Windows 11 23h2, both same company policies.

When I remove the integration from my old laptop, it immideately gets rediscovered after a reboot of HA. My new laptop just doesn't get discovered. I thought it maybe was due to the name of my laptop device, but that doesn't seem to matter.

When I enable extended logging I'm getting a error in the log:

2024-07-15 21:14:18.432 +02:00 [FTL] [PROGRAM] FirstChanceException: Unable to cast COM object of type 'System.__ComObject' to interface type 'NAudio.CoreAudioApi.Interfaces.IMMDevice'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{D666063F-1587-4E43-81F1-B948E807363F}' failed due to the following error: Interface wordt niet ondersteund (0x80004002 (E_NOINTERFACE)).
System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'NAudio.CoreAudioApi.Interfaces.IMMDevice'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{D666063F-1587-4E43-81F1-B948E807363F}' failed due to the following error: Interface wordt niet ondersteund (0x80004002 (E_NOINTERFACE)).
   at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, IntPtr& ppTarget, Boolean& pfNeedsRelease)
   at NAudio.CoreAudioApi.Interfaces.IMMDevice.GetState(DeviceState& state)
   at NAudio.CoreAudioApi.MMDevice.get_State()
   at HASS.Agent.Shared.Managers.Audio.AudioManager.<>c.<GetDevices>b__18_0(InternalAudioDevice d) in D:\a\HASS.Agent\HASS.Agent\src\HASS.Agent\HASS.Agent.Shared\Managers\Audio\AudioManager.cs:line 225
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at HASS.Agent.Shared.Managers.Audio.AudioManager.GetDevices() in D:\a\HASS.Agent\HASS.Agent\src\HASS.Agent\HASS.Agent.Shared\Managers\Audio\AudioManager.cs:line 225

To Reproduce I can't reproduce it on my old laptop device, but my new one doesn't work at all with notifications. Sensors and all other stuff work just fine.

When the device get's discovered, it doesn't create a notify service, which it does on my old laptop.

Expected behavior

Screenshots If applicable, add screenshots to help explain your problem.

Misc info (please complete the following information):

Please check what's applicable (multiple answers possible):

Additional context All information gets pushed to MQTT. There must be something wrong, but I can't seem to grasp the difference between the two laptops. In MQTT it also seems to be the same.

Logs [2024-07-15] HASS.Agent_20240715.log

amadeo-alex commented 2 months ago

I'll close this one and keep the integration issue open https://github.com/hass-agent/HASS.Agent-Integration/issues/5 - at least the first one related to the integration. The second one related to COM objects of audio sensors/commands has been fixed with https://github.com/hass-agent/HASS.Agent/pull/122 and will be included as part of beta3 (alpha build of alpha3 can be found here https://github.com/amadeo-alex/HASS.Agent/releases/tag/2.1.0-beta3-testbuild1)