Fix __repr__ crash when get_device_info returns SmartErrorCode by loganrosen · Pull Request #1672 · python-kasa/python-kasa
When a device returns INTERNAL_QUERY_ERROR for get_device_info, the response is stored as a SmartErrorCode enum in _last_update. If another module then raises DeviceError and the error is logged with %s formatting, __repr__ calls self.model which calls _get_device_info, crashing with TypeError: 'SmartErrorCode' object is not subscriptable. Make __repr__ resilient by catching exceptions and falling back to a basic representation without alias/model. This follows the Python convention that __repr__ should never raise. Fixes python-kasa#1671 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>