Skip to content

Commit

Permalink
Fix Pylint issues (#355)
Browse files Browse the repository at this point in the history
* fix consider-using-in

* fix f-string-without-interpolation

* fix logging-not-lazy

* fix logging-fstring-interpolation

* fix pointless-string-statement

* fix format

* fix no-else-raise

* fix no-else-return
  • Loading branch information
CFenner authored Feb 18, 2024
1 parent 2afa501 commit 6c5b023
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 179 deletions.
9 changes: 1 addition & 8 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
disable=
duplicate-code,
fixme,
format,
line-too-long,
invalid-name,
too-many-public-methods,
too-few-public-methods,
Expand All @@ -16,18 +16,11 @@ disable=
consider-merging-isinstance,
consider-using-dict-items,
consider-using-generator,
consider-using-in,
deprecated-decorator,
f-string-without-interpolation,
logging-fstring-interpolation,
logging-not-lazy,
missing-class-docstring,
missing-function-docstring,
missing-module-docstring,
missing-timeout,
no-else-raise,
no-else-return,
pointless-string-statement,
raise-missing-from,
super-init-not-called,
too-many-boolean-expressions,
Expand Down
13 changes: 5 additions & 8 deletions PyViCare/PyViCare.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
logger = logging.getLogger('ViCare')
logger.addHandler(logging.NullHandler())

""""Viessmann ViCare API Python tools"""


class PyViCare:
""""Viessmann ViCare API Python tools"""
def __init__(self) -> None:
self.cacheDuration = 60

Expand All @@ -36,8 +35,7 @@ def initWithBrowserOAuth(self, client_id: str, token_file: str) -> None:
def __buildService(self, accessor, roles):
if self.cacheDuration > 0:
return ViCareCachedService(self.oauth_manager, accessor, roles, self.cacheDuration)
else:
return ViCareService(self.oauth_manager, accessor, roles)
return ViCareService(self.oauth_manager, accessor, roles)

def __loadInstallations(self):
installations = self.oauth_manager.get(
Expand All @@ -54,7 +52,7 @@ def __extract_devices(self):
for installation in self.installations:
for gateway in installation.gateways:
for device in gateway.devices:
if device.deviceType != "heating" and device.deviceType != "zigbee" and device.deviceType != "vitoconnect" and device.deviceType != "electricityStorage" and device.deviceType != "EEBus" and device.deviceType != "hems" and device.deviceType != "tcu" and device.deviceType != "ventilation":
if device.deviceType not in ["heating", "zigbee", "vitoconnect", "electricityStorage", "EEBus", "hems", "tcu", "ventilation"]:
continue # we are only interested in heating, photovoltaic, electricityStorage, hems and ventilation devices

if device.id == "gateway" and device.deviceType == "vitoconnect":
Expand All @@ -73,7 +71,7 @@ def __extract_devices(self):
installation.id, gateway.serial, device.id)
service = self.__buildService(accessor, device.roles)

logger.info(f"Device found: {device.modelId}")
logger.info("Device found: %s", device.modelId)

yield PyViCareDeviceConfig(service, device.id, device.modelId, device.status)

Expand All @@ -91,5 +89,4 @@ def Wrap(v):
return DictWrap(v)
if isinstance(v, str) and len(v) == 24 and v[23] == 'Z' and v[10] == 'T':
return datetime.strptime(v, '%Y-%m-%dT%H:%M:%S.%f%z')
else:
return v
return v
29 changes: 14 additions & 15 deletions PyViCare/PyViCareAbstractOAuthManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get(self, url: str) -> Any:
try:
logger.debug(self.__oauth)
response = self.__oauth.get(f"{API_BASE_URL}{url}", timeout=31).json()
logger.debug(f"Response to get request: {response}")
logger.debug("Response to get request: %s", response)
self.__handle_expired_token(response)
self.__handle_rate_limit(response)
self.__handle_server_error(response)
Expand Down Expand Up @@ -69,21 +69,20 @@ def __handle_command_error(self, response):
if ("statusCode" in response and response["statusCode"] >= 400):
raise PyViCareCommandError(response)

"""POST URL using OAuth session. Automatically renew the token if needed
Parameters
----------
url : str
URL to get
data : str
Data to post
Returns
-------
result: json
json representation of the answer
"""

def post(self, url, data) -> Any:
"""POST URL using OAuth session. Automatically renew the token if needed
Parameters
----------
url : str
URL to get
data : str
Data to post
Returns
-------
result: json
json representation of the answer
"""
headers = {"Content-Type": "application/json",
"Accept": "application/vnd.siren+json"}
try:
Expand Down
4 changes: 2 additions & 2 deletions PyViCare/PyViCareBrowserOAuthManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ def handlerWithCallbackWrapper(*args):
logger.debug("Timeout reached")
raise PyViCareBrowserOAuthTimeoutReachedError()

logger.debug(f"Location: {location}")
logger.debug("Location: %s", location)

oauth_session.fetch_token(TOKEN_URL, authorization_response=location, code_verifier=code_verifier)

if oauth_session.token is None:
raise PyViCareInvalidCredentialsError()

logger.debug(f"Token received: {oauth_session.token}")
logger.debug("Token received: %s", oauth_session.token)
self.__storeToken(oauth_session.token)
logger.info("New token created")
return oauth_session
Expand Down
7 changes: 3 additions & 4 deletions PyViCare/PyViCareDeviceConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def asRoomSensor(self):

def asElectricalEnergySystem(self):
return ElectricalEnergySystem(self.service)

def asGateway(self):
return Gateway(self.service)

Expand Down Expand Up @@ -94,11 +94,10 @@ def asAutoDetectDevice(self):

for (creator_method, type_name, roles) in device_types:
if re.search(type_name, self.device_model) or self.service.hasRoles(roles):
logger.info(f"detected {self.device_model} {creator_method.__name__}")
logger.info("detected %s %s", self.device_model, creator_method.__name__)
return creator_method()

logger.info(
f"Could not auto detect {self.device_model}. Use generic device.")
logger.info("Could not auto detect %s. Use generic device.", self.device_model)
return self.asGeneric()

def get_raw_json(self):
Expand Down
Loading

0 comments on commit 6c5b023

Please sign in to comment.