Moved optional import in constructor block.

This commit is contained in:
Fabio Manganiello 2024-01-07 00:05:51 +01:00
parent 1ff8cfd240
commit f733c6318f
Signed by: blacklight
GPG key ID: D90FBA7F76362774

View file

@ -1,7 +1,5 @@
import time import time
import platypush.plugins.gpio.zeroborg.lib as ZeroBorg
from platypush.backend import Backend from platypush.backend import Backend
from platypush.message.event.sensor.ir import IrKeyUpEvent, IrKeyDownEvent from platypush.message.event.sensor.ir import IrKeyUpEvent, IrKeyDownEvent
@ -20,6 +18,8 @@ class SensorIrZeroborgBackend(Backend):
last_message_timestamp = None last_message_timestamp = None
def __init__(self, no_message_timeout=0.37, **kwargs): def __init__(self, no_message_timeout=0.37, **kwargs):
import platypush.plugins.gpio.zeroborg.lib as ZeroBorg
super().__init__(**kwargs) super().__init__(**kwargs)
self.no_message_timeout = no_message_timeout self.no_message_timeout = no_message_timeout
self.zb = ZeroBorg.ZeroBorg() self.zb = ZeroBorg.ZeroBorg()
@ -36,9 +36,7 @@ class SensorIrZeroborgBackend(Backend):
message = self.zb.GetIrMessage() message = self.zb.GetIrMessage()
if message != self.last_message: if message != self.last_message:
self.logger.info( self.logger.info(
'Received key down event on the IR sensor: {}'.format( 'Received key down event on the IR sensor: %s', message
message
)
) )
self.bus.post(IrKeyDownEvent(message=message)) self.bus.post(IrKeyDownEvent(message=message))
@ -46,7 +44,7 @@ class SensorIrZeroborgBackend(Backend):
self.last_message_timestamp = time.time() self.last_message_timestamp = time.time()
except OSError as e: except OSError as e:
self.logger.warning( self.logger.warning(
'Failed reading IR sensor status: {}: {}'.format(type(e), str(e)) 'Failed reading IR sensor status: %s: %s', type(e), e
) )
if ( if (