Update keyboard_remote.py (#5112)
Update keyboard_remote.py (#5112)

* Update keyboard_remote.py

I changed os.path.isFile() to os.path.exists: as far as I know isFile doesn't work with device files. At least on my Ubuntu it wasn't working.

Then I added some error control in case the keyboard disconnects: with bluetooth keyboards this happen often due to battery saving. Now it reconnects automatically when the keyboard wakes up.

We could fire an event to hass when the keyboard connects-disconnects, maybe I'll do this later.

We should also manage errors due to permissions problems on the device file, or at least give some info in the docs about how to allow HA to grab control over an system input file.

I'm sorry if my coding isn't up to some standard practice I'm not aware of: I'm new to HA and to python itself, I'm just trying to be of help.
Gianluca

* Update keyboard_remote.py

I changed some other few things.

Not the component gets loaded even if the keyboard is disconnected. When it connects, it starts to fire events when keys are pressed.

I also added a sleep(0.1) that reduces a lot the load on the CPU, but without many consequences on key pressed detection.

PetePriority/home-assistant,jnewland/home-assistant,LinuxChristian/home-assistant,titilambert/home-assistant,alexmogavero/home-assistant,tboyce021/home-assistant,robbiet480/home-assistant,robjohnson189/home-assistant,eagleamon/home-assistant,ewandor/home-assistant,mKeRix/home-assistant,sdague/home-assistant,DavidLP/home-assistant,rohitranjan1991/home-assistant,soldag/home-assistant,kyvinh/home-assistant,jamespcole/home-assistant,ct-23/home-assistant,ewandor/home-assistant,keerts/home-assistant,adrienbrault/home-assistant,lukas-hetzenecker/home-assistant,miniconfig/home-assistant,morphis/home-assistant,tboyce1/home-assistant,JshWright/home-assistant,nugget/home-assistant,Duoxilian/home-assistant,shaftoe/home-assistant,turbokongen/home-assistant,tboyce1/home-assistant,molobrakos/home-assistant,jawilson/home-assistant,auduny/home-assistant,titilambert/home-assistant,PetePriority/home-assistant,HydrelioxGitHub/home-assistant,Cinntax/home-assistant,Teagan42/home-assistant,molobrakos/home-assistant,sander76/home-assistant,jawilson/home-assistant,shaftoe/home-assistant,persandstrom/home-assistant,tchellomello/home-assistant,toddeye/home-assistant,MungoRae/home-assistant,LinuxChristian/home-assistant,mKeRix/home-assistant,FreekingDean/home-assistant,balloob/home-assistant,balloob/home-assistant,robjohnson189/home-assistant,w1ll1am23/home-assistant,Teagan42/home-assistant,persandstrom/home-assistant,turbokongen/home-assistant,GenericStudent/home-assistant,Zac-HD/home-assistant,lukas-hetzenecker/home-assistant,home-assistant/home-assistant,tinloaf/home-assistant,Zac-HD/home-assistant,alexmogavero/home-assistant,aronsky/home-assistant,eagleamon/home-assistant,fbradyirl/home-assistant,Duoxilian/home-assistant,nugget/home-assistant,mezz64/home-assistant,toddeye/home-assistant,tboyce1/home-assistant,eagleamon/home-assistant,keerts/home-assistant,MartinHjelmare/home-assistant,MungoRae/home-assistant,qedi-r/home-assistant,sdague/home-assistant,kennedyshead/home-assistant,postlund/home-assistant,tboyce1/home-assistant,robjohnson189/home-assistant,Cinntax/home-assistant,MungoRae/home-assistant,stefan-jonasson/home-assistant,MungoRae/home-assistant,happyleavesaoc/home-assistant,DavidLP/home-assistant,leppa/home-assistant,soldag/home-assistant,home-assistant/home-assistant,Duoxilian/home-assistant,open-homeautomation/home-assistant,w1ll1am23/home-assistant,jabesq/home-assistant,jamespcole/home-assistant,qedi-r/home-assistant,aequitas/home-assistant,HydrelioxGitHub/home-assistant,ct-23/home-assistant,MartinHjelmare/home-assistant,postlund/home-assistant,JshWright/home-assistant,sander76/home-assistant,mKeRix/home-assistant,FreekingDean/home-assistant,nugget/home-assistant,ct-23/home-assistant,keerts/home-assistant,jamespcole/home-assistant,LinuxChristian/home-assistant,happyleavesaoc/home-assistant,mezz64/home-assistant,tboyce021/home-assistant,joopert/home-assistant,aequitas/home-assistant,pschmitt/home-assistant,partofthething/home-assistant,shaftoe/home-assistant,JshWright/home-assistant,happyleavesaoc/home-assistant,stefan-jonasson/home-assistant,pschmitt/home-assistant,keerts/home-assistant,robjohnson189/home-assistant,morphis/home-assistant,kennedyshead/home-assistant,stefan-jonasson/home-assistant,morphis/home-assistant,LinuxChristian/home-assistant,balloob/home-assistant,kyvinh/home-assistant,open-homeautomation/home-assistant,happyleavesaoc/home-assistant,joopert/home-assistant,Danielhiversen/home-assistant,Danielhiversen/home-assistant,DavidLP/home-assistant,aronsky/home-assistant,morphis/home-assistant,miniconfig/home-assistant,tchellomello/home-assistant,molobrakos/home-assistant,fbradyirl/home-assistant,nkgilley/home-assistant,jnewland/home-assistant,miniconfig/home-assistant,kyvinh/home-assistant,tinloaf/home-assistant,nkgilley/home-assistant,auduny/home-assistant,open-homeautomation/home-assistant,eagleamon/home-assistant,rohitranjan1991/home-assistant,HydrelioxGitHub/home-assistant,open-homeautomation/home-assistant,jabesq/home-assistant,tinloaf/home-assistant,persandstrom/home-assistant,leppa/home-assistant,robbiet480/home-assistant,aequitas/home-assistant,LinuxChristian/home-assistant,ct-23/home-assistant,jnewland/home-assistant,auduny/home-assistant,Zac-HD/home-assistant,alexmogavero/home-assistant,adrienbrault/home-assistant,GenericStudent/home-assistant,ct-23/home-assistant,fbradyirl/home-assistant,Duoxilian/home-assistant,ewandor/home-assistant,MungoRae/home-assistant,stefan-jonasson/home-assistant,PetePriority/home-assistant,kyvinh/home-assistant,MartinHjelmare/home-assistant,miniconfig/home-assistant,shaftoe/home-assistant,rohitranjan1991/home-assistant,mKeRix/home-assistant,jabesq/home-assistant,partofthething/home-assistant,JshWright/home-assistant,Zac-HD/home-assistant,alexmogavero/home-assistant