LAB02-Research / HASS.Agent

Windows-based client for Home Assistant. Provides notifications, quick actions, commands, sensors and more.
https://hassagent.lab02-research.org
MIT License
1.58k stars 70 forks source link

Bug: LastSystemStateChange reporting different values #211

Open ITensEI opened 1 year ago

ITensEI commented 1 year ago

Describe the bug I have HASS.Agent installed on my PC and a VM. I use the sensor to automate my VM by sending commands to it. When the VM starts I look for LastSystemStateChange sensor to switch from Unavailable to ApplicationStarted. Worked fine until my VM automation stopped working. I noticed the sensor now reports ConsoleConnect on start. Not an issue I just added that to my automation flow, but my PC is still reports ApplicationStarted. Both are running 2022.13 so I'm wondering why the difference and why it happened seemingly random.

PC Satellite Service Logs only show [LIFETIMEMANAGER] SessionChange: SessionLogon

While VM ones show both [LIFETIMEMANAGER] SessionChange: ConsoleConnect [LIFETIMEMANAGER] SessionChange: SessionLogon

To Reproduce Steps to reproduce the behavior: Boot PC LastSystemStateChange = ApplicationStarted Start VM LastSystemStateChange = ConsoleConnect Both running same version of HASS.Agent

Expected behavior Both sensors to report the same values

Screenshots image The yellow bit is the Application Started

Misc info (please complete the following information):

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

LAB02-Admin commented 1 year ago

Thanks for the detailed report, I'll look into it: [hassagent-190]

amadeo-alex commented 1 year ago

I'm not 100% sure this is actually a bug. The difference my come from the fact the for the VM a console (part of the emulation of someone actually being present at the "device" aka "mstsc /admin" or "mstsc /console" on legacy systems) is actually attached by the VM management software which is not happening on real life hardware/OS install. https://learn.microsoft.com/en-us/dotnet/api/microsoft.win32.sessionswitchreason?view=windowsdesktop-7.0 https://learn.microsoft.com/en-us/troubleshoot/windows-server/remote/connect-to-and-shadow-console-session

The only thing I'm wondering is why it changed, from what you described this wasn't working like that. I'm more leaning towards the statement that it was working incorrectly then and now is how it should from the start but this is just me thinking aloud. (VM management software update maybe?)