Skip to content

util.ignore_exception calls are silently failing #41

Description

@PortableProgrammer

For int environment variables (ex: TUYA_BRIGHTNESS), the existing code below doesn't work as intended, which then simply sets the environment variable to the default value.

# In env.pyself.tuyaBrightness=128
...
brightness_try_parse=util.ignore_exception(ValueError, self.tuyaBrightness)(int)
self.tuyaBrightness=brightness_try_parse(os.environ.get('TUYA_BRIGHTNESS', self.tuyaBrightness))

We should switch to a less-complex method to parse the integer from a string, i.e.

# In util.pydeftry_parse_int(value, base=10, default=None):
try:
returnint(value, base)
exceptValueError:
returnvalue# In env.pyself.tuyaBrightness=util.try_parse_int(os.environ.get('TUYA_BRIGHTNESS'), default=self.tuyaBrightness)

Metadata

Metadata

Labels

bugSomething isn't workingenhancementNew feature or request

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions