26
26
27
27
SERVICE_SET_MODE_SCHEMA = vol .Schema ({vol .Required (ATTR_ALWAYS_ON_NAME ): cv .boolean })
28
28
29
+ I2C_ADDRESS = 0x1A
30
+
29
31
30
32
async def async_setup (hass : HomeAssistantType , config : ConfigType ) -> bool :
31
33
"""Set up the Argon40 component."""
@@ -68,22 +70,21 @@ def event_detect_callback(channel):
68
70
69
71
GPIO .add_event_detect (shutdown_pin , GPIO .BOTH , callback = event_detect_callback )
70
72
71
- address = 0x1A
72
- bus .write_byte (address , 10 )
73
+ bus .write_byte (I2C_ADDRESS , 10 )
73
74
74
75
except IOError as err :
75
76
_LOGGER .exception (
76
77
"Error %d, %s accessing 0x%02X: Check your I2C address" ,
77
78
err .errno ,
78
79
err .strerror ,
79
- address ,
80
+ I2C_ADDRESS ,
80
81
)
81
82
return False
82
83
83
84
async def set_fan_speed (service : ServiceDataType ) -> None :
84
85
value = service .data .get (ATTR_SPEED_NAME )
85
86
_LOGGER .debug ("Set fan speed to %s" , value )
86
- bus .write_byte (address , value )
87
+ bus .write_byte (I2C_ADDRESS , value )
87
88
hass .bus .async_fire ("argon40_event" , {"speed" : value })
88
89
89
90
hass .services .async_register (
@@ -97,9 +98,9 @@ async def set_mode(service: ServiceDataType) -> None:
97
98
value = service .data .get (ATTR_ALWAYS_ON_NAME )
98
99
_LOGGER .debug ("Set always on mode to %s" , value )
99
100
if value :
100
- bus .write_byte (address , 254 ) # 0xfe - always on mode
101
+ bus .write_byte (I2C_ADDRESS , 254 ) # 0xfe - always on mode
101
102
else :
102
- bus .write_byte (address , 253 ) # 0xfd - the default mode
103
+ bus .write_byte (I2C_ADDRESS , 253 ) # 0xfd - the default mode
103
104
104
105
hass .bus .async_fire ("argon40_event" , {"always_on" : value })
105
106
0 commit comments