Skip to content

Commit 45a5328

Browse files
authored
Merge pull request #18 from vondras/patch-1
Replace i2c address with a constant
2 parents c22d90e + d8f7339 commit 45a5328

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

custom_components/argon40/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
SERVICE_SET_MODE_SCHEMA = vol.Schema({vol.Required(ATTR_ALWAYS_ON_NAME): cv.boolean})
2828

29+
I2C_ADDRESS = 0x1A
30+
2931

3032
async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool:
3133
"""Set up the Argon40 component."""
@@ -68,22 +70,21 @@ def event_detect_callback(channel):
6870

6971
GPIO.add_event_detect(shutdown_pin, GPIO.BOTH, callback=event_detect_callback)
7072

71-
address = 0x1A
72-
bus.write_byte(address, 10)
73+
bus.write_byte(I2C_ADDRESS, 10)
7374

7475
except IOError as err:
7576
_LOGGER.exception(
7677
"Error %d, %s accessing 0x%02X: Check your I2C address",
7778
err.errno,
7879
err.strerror,
79-
address,
80+
I2C_ADDRESS,
8081
)
8182
return False
8283

8384
async def set_fan_speed(service: ServiceDataType) -> None:
8485
value = service.data.get(ATTR_SPEED_NAME)
8586
_LOGGER.debug("Set fan speed to %s", value)
86-
bus.write_byte(address, value)
87+
bus.write_byte(I2C_ADDRESS, value)
8788
hass.bus.async_fire("argon40_event", {"speed": value})
8889

8990
hass.services.async_register(
@@ -97,9 +98,9 @@ async def set_mode(service: ServiceDataType) -> None:
9798
value = service.data.get(ATTR_ALWAYS_ON_NAME)
9899
_LOGGER.debug("Set always on mode to %s", value)
99100
if value:
100-
bus.write_byte(address, 254) # 0xfe - always on mode
101+
bus.write_byte(I2C_ADDRESS, 254) # 0xfe - always on mode
101102
else:
102-
bus.write_byte(address, 253) # 0xfd - the default mode
103+
bus.write_byte(I2C_ADDRESS, 253) # 0xfd - the default mode
103104

104105
hass.bus.async_fire("argon40_event", {"always_on": value})
105106

0 commit comments

Comments
 (0)