Skip to content

Conversation

lbbrhzn
Copy link
Owner

@lbbrhzn lbbrhzn commented Jul 30, 2021

No description provided.

@github-actions
Copy link

github-actions bot commented Jul 30, 2021

🎉 HACS repository validator action summary 🎉
✅ The repository is not archived
✅ manifest.json file exist
✅ All required keys are present in manifest.json
✅ hacs.json has the 'name' key set
✅ The repository has a description
⚪ Ignored check: brands
✅ The repository has topics
✅ The repository has issues enabled
✅ This day ends with an 'y' (Saturday)
✅ README.md exists
✅ Requirements validation
✅ Python wheels
✅ HACS load check

@ghost
Copy link

ghost commented Jul 30, 2021

Congratulations 🎉. DeepCode analyzed your code in 3.82 seconds and we found no issues. Enjoy a moment of no bugs ☀️.

👉 View analysis in DeepCode’s Dashboard | Configure the bot

👉 The DeepCode service and API will be deprecated in August, 2021. Here is the information how to migrate. Thank you for using DeepCode 🙏 ❤️ !

If you are using our plugins, you might be interested in their successors: Snyk's JetBrains plugin and Snyk's VS Code plugin.

@lbbrhzn lbbrhzn marked this pull request as ready for review July 30, 2021 21:43
@lbbrhzn lbbrhzn requested a review from drc38 July 30, 2021 21:43
@drc38
Copy link
Collaborator

drc38 commented Jul 31, 2021

@lbbrhzn , sorry I appear to have made a mistake trying to merge your metrics_class into my repo for testing. Are you able to revert this as I can't seem to?

@lbbrhzn
Copy link
Owner Author

lbbrhzn commented Jul 31, 2021

yes. I did:

git reset dae06b
git push --force origin

@@ -793,23 +796,27 @@ def on_meter_values(self, connector_id: int, meter_value: Dict, **kwargs):
processed_keys = []
for idx, sv in enumerate(bucket[om.sampled_value.name]):
if m in sv and om.phase.value not in sv:
self._metrics[sv[m]] = round(float(sv[om.value.value]), 1)
self._metrics[sv[m]].value = round(float(sv[om.value.value]), 1)
if om.unit.value in sv:
if sv[om.unit.value] == DEFAULT_POWER_UNIT:
Copy link
Collaborator

@drc38 drc38 Jul 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not as a result of your changes but in reviewing I've noticed there should be a line here to set the units:
self._metrics[sv[m]].unit = sv[om.unit.value]
Directly after the statement if om.unit.value in sv: that is...

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I'll add that

@@ -167,27 +168,30 @@ async def on_connect(self, websocket, path: str):
cp = self.charge_points[self.cpid]
await self.charge_points[self.cpid].reconnect(websocket)
except Exception as e:
_LOGGER.info(f"Exception occurred:\n{e}")
_LOGGER.error(f"Exception occurred:\n{e}", exc_info=True)

finally:
self.charge_points[self.cpid].status = STATE_UNAVAILABLE
_LOGGER.info(f"Charger {cp_id} disconnected from {self.host}:{self.port}.")

def get_metric(self, cp_id: str, measurand: str):
"""Return last known value for given measurand."""
if cp_id in self.charge_points:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need and (measurand in self.charge_points[cp_id]._metrics) as per lines 191-193?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. I've made _metrics a defaultdict. As a result, any metric that is not (yet) defined will have default values (None)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useful to know as I was having lots of issues with missing dictionary values.

Does that also mean and (measurand in self.charge_points[cp_id]._metrics) can be removed from lines 191-193?

finally:
self.charge_points[self.cpid].status = STATE_UNAVAILABLE
_LOGGER.info(f"Charger {cp_id} disconnected from {self.host}:{self.port}.")

def get_metric(self, cp_id: str, measurand: str):
"""Return last known value for given measurand."""
if cp_id in self.charge_points:
return self.charge_points[cp_id].get_metric(measurand)
return self.charge_points[cp_id]._metrics[measurand].value
return None

def get_unit(self, cp_id: str, measurand: str):
"""Return unit of given measurand."""
if cp_id in self.charge_points:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per comment above

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. I've made metrics a defaultdict. As a result, any metric that is not (yet) defined will have default values (None)

Copy link
Collaborator

@drc38 drc38 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@lbbrhzn lbbrhzn merged commit b6d98f6 into main Jul 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants