robert-alfaro / xfinity-usage

Home Assistant custom component for retrieving Xfinity data usage
53 stars 19 forks source link

Fails to retrieve data - due to unlimited plan? #3

Closed schoenof closed 4 years ago

schoenof commented 4 years ago

This fails to load any data for me with error below: I suspect it is because I am on the 1gig plan (no cap)...maybe allowed_usage is not getting populated due to the unlimited....I know I might not be the main use case since I have unlimited but still would be interesting to see this in HA...

Log Details (ERROR) Mon Dec 16 2019 09:19:47 GMT-0500 (Eastern Standard Time) Error doing job: Future exception was never retrieved Traceback (most recent call last): File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/config/custom_components/xfinity/sensor.py", line 50, in hass.bus.listen_once(EVENT_HOMEASSISTANTSTART, lambda : _first_run()) File "/config/custom_components/xfinity/sensor.py", line 46, in _first_run sensor.update() File "/config/custom_components/xfinity/sensor.py", line 99, in update self._xfinity_data.update() File "/config/custom_components/xfinity/sensor.py", line 162, in update self.remaining_usage = self.allowed_usage - self.total_usage TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'

Environment HA 103.0 component installed via HACS running in hassio on ubuntu

schoenof commented 4 years ago

Not sure how you are scaping the data but the top of the data usage section looks like below for me:

Monthly Data Usage 1234GB used this month (December 01 - December 31). Data used in the last 24 hours may not be displayed

nnhhuu commented 4 years ago

i have a similar error...

2020 -01-07 19:25:06 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved Traceback (most recent call last): File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/config/custom_components/xfinity/sensor.py", line 50, in hass.bus.listen_once(EVENT_HOMEASSISTANTSTART, lambda : _first_run()) File "/config/custom_components/xfinity/sensor.py", line 46, in _first_run sensor.update() File "/config/custom_components/xfinity/sensor.py", line 99, in update self._xfinity_data.update() File "/config/custom_components/xfinity/sensor.py", line 162, in update self.remaining_usage = self.allowed_usage - self.total_usage TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'

nnhhuu commented 4 years ago

Robert, thank you for your response .... I have an unlimited plan, no two Factor authentication, installed with hacs. Thanks again

robert-alfaro commented 4 years ago

I don't have unlimited plan to test this, however, I'll kindly ask one of you to help me test. First thing is I'll expose all the response fields to the state attributes, secondly I'll add some checks to see which field it is that is None...I suspect allowed_usage is not populated.

schoenof commented 4 years ago

Sure I'll help...just let me know what you need me to do...

SamMcDowell commented 4 years ago

Giving the custom component a try, found that it's failing for me as well. Definitely due to my account somehow being set to unlimited. With that, allowableUsage = None. If this help, using the HASS debug logger, my last month in the JSON looks like:

{'policyName':` 'Unlimited Data Plan', 'startDate': '01/01/2020', 'endDate': '01/31/2020', 'homeUsage': 453.0, 'wifiUsage': 0.0, 'totalUsage': 453.0, 'allowableUsage': None, 'unitOfMeasure': 'GB', 'devices': [{'id': 'XXXX', 'usage': 453.0}], 'additionalBlocksUsed': 0.0, 'additionalCostPerBlock': 0.0, 'additionalUnitsPerBlock': None, 'additionalIncluded': 0.0, 'additionalUsed': 0.0, 'additionalPercentUsed': 0.0, 'additionalRemaining': 0.0, 'billableOverage': 0.0, 'overageCharges': 0.0, 'overageUsed': 0.0, 'currentCreditAmount': 0, 'maxCreditAmount': 0, 'policy': 'unlimited'}

I made a small change on my side to get it working in my custom_components - just check for allowed_usage in order to calculate remaining_usage.

-Sam

robert-alfaro commented 4 years ago

Just pushed a branch named bugfix/unlimited-data, hopefully can start debugging this problem. I have not [yet] tested the changes myself.

robert-alfaro commented 4 years ago

@SamMcDowell @schoenof ?

SamMcDowell commented 4 years ago

Sorry, I missed this @robert-alfaro. I will update my instance with your changes tonight to confirm they address the issue. Thanks, Sam

SamMcDowell commented 4 years ago

Hi @robert-alfaro, I just did a quick test of your changes. No issues getting and displaying the monthly usage. Exactly what I was looking for. I'm currently running the bugfix version with my HASS custom components. Thanks, Sam

robert-alfaro commented 4 years ago

Great! Any chance you can paste debug logs for this component (I don't have unlimited plan and am curious if some logging)?

SamMcDowell commented 4 years ago

Sure thing. Here's the debug log. Let me know if you'd like any other details...

Received usage data: {'courtesyUsed': 0, 'courtesyRemaining': 2, 'courtesyAllowed': 2, 'inPaidOverage': False, 'usageMonths': [{'policyName': '1 Terabyte Data Plan', 'startDate': '07/01/2019', 'endDate': '07/31/2019', 'homeUsage': 966.0, 'wifiUsage': 0.0, 'totalUsage': 966.0, 'allowableUsage': 1024.0, 'unitOfMeasure': 'GB', 'devices': [], 'additionalBlocksUsed': 0.0, 'additionalCostPerBlock': 10.0, 'additionalUnitsPerBlock': 50.0, 'additionalIncluded': 0.0, 'additionalUsed': 0.0, 'additionalPercentUsed': 0.0, 'additionalRemaining': 0.0, 'billableOverage': 0.0, 'overageCharges': 0.0, 'overageUsed': 0.0, 'currentCreditAmount': 0, 'maxCreditAmount': 0, 'policy': 'limited'}, {'policyName': '1 Terabyte Data Plan', 'startDate': '08/01/2019', 'endDate': '08/31/2019', 'homeUsage': 700.0, 'wifiUsage': None, 'totalUsage': 700.0, 'allowableUsage': 1024.0, 'unitOfMeasure': 'GB', 'devices': [], 'additionalBlocksUsed': 0.0, 'additionalCostPerBlock': 10.0, 'additionalUnitsPerBlock': 50.0, 'additionalIncluded': 0.0, 'additionalUsed': 0.0, 'additionalPercentUsed': 0.0, 'additionalRemaining': 0.0, 'billableOverage': 0.0, 'overageCharges': 0.0, 'overageUsed': 0.0, 'currentCreditAmount': 0, 'maxCreditAmount': 0, 'policy': 'limited'}, {'policyName': '1 Terabyte Data Plan', 'startDate': '09/01/2019', 'endDate': '09/30/2019', 'homeUsage': 864.0, 'wifiUsage': None, 'totalUsage': 864.0, 'allowableUsage': 1024.0, 'unitOfMeasure': 'GB', 'devices': [{'id': 'xxxx', 'usage': 864.0}], 'additionalBlocksUsed': 0.0, 'additionalCostPerBlock': 10.0, 'additionalUnitsPerBlock': 50.0, 'additionalIncluded': 0.0, 'additionalUsed': 0.0, 'additionalPercentUsed': 0.0, 'additionalRemaining': 0.0, 'billableOverage': 0.0, 'overageCharges': 0.0, 'overageUsed': 0.0, 'currentCreditAmount': 0, 'maxCreditAmount': 0, 'policy': 'limited'}, {'policyName': '1 Terabyte Data Plan', 'startDate': '10/01/2019', 'endDate': '10/31/2019', 'homeUsage': 1004.0, 'wifiUsage': 0.0, 'totalUsage': 1004.0, 'allowableUsage': 1024.0, 'unitOfMeasure': 'GB', 'devices': [{'id': 'xxxx', 'usage': 1004.0}], 'additionalBlocksUsed': 0.0, 'additionalCostPerBlock': 10.0, 'additionalUnitsPerBlock': 50.0, 'additionalIncluded': 0.0, 'additionalUsed': 0.0, 'additionalPercentUsed': 0.0, 'additionalRemaining': 0.0, 'billableOverage': 0.0, 'overageCharges': 0.0, 'overageUsed': 0.0, 'currentCreditAmount': 0, 'maxCreditAmount': 0, 'policy': 'limited'}, {'policyName': '1 Terabyte Data Plan', 'startDate': '11/01/2019', 'endDate': '11/30/2019', 'homeUsage': 926.0, 'wifiUsage': 0.0, 'totalUsage': 926.0, 'allowableUsage': 1024.0, 'unitOfMeasure': 'GB', 'devices': [{'id': 'xxxxx', 'usage': 926.0}], 'additionalBlocksUsed': 0.0, 'additionalCostPerBlock': 10.0, 'additionalUnitsPerBlock': 50.0, 'additionalIncluded': 0.0, 'additionalUsed': 0.0, 'additionalPercentUsed': 0.0, 'additionalRemaining': 0.0, 'billableOverage': 0.0, 'overageCharges': 0.0, 'overageUsed': 0.0, 'currentCreditAmount': 0, 'maxCreditAmount': 0, 'policy': 'limited'}, {'policyName': 'Unlimited Data Plan', 'startDate': '12/01/2019', 'endDate': '12/31/2019', 'homeUsage': 1146.0, 'wifiUsage': 0.0, 'totalUsage': 1146.0, 'allowableUsage': None, 'unitOfMeasure': 'GB', 'devices': [{'id': 'xxx', 'usage': 410.0}, {'id': 'xxx', 'usage': 736.0}], 'additionalBlocksUsed': 0.0, 'additionalCostPerBlock': 0.0, 'additionalUnitsPerBlock': None, 'additionalIncluded': 0.0, 'additionalUsed': 0.0, 'additionalPercentUsed': 0.0, 'additionalRemaining': 0.0, 'billableOverage': 0.0, 'overageCharges': 0.0, 'overageUsed': 0.0, 'currentCreditAmount': 0, 'maxCreditAmount': 0, 'policy': 'unlimited'}, {'policyName': 'Unlimited Data Plan', 'startDate': '01/01/2020', 'endDate': '01/31/2020', 'homeUsage': 619.0, 'wifiUsage': 0.0, 'totalUsage': 619.0, 'allowableUsage': None, 'unitOfMeasure': 'GB', 'devices': [{'id': 'xxxx', 'usage': 619.0}], 'additionalBlocksUsed': 0.0, 'additionalCostPerBlock': 0.0, 'additionalUnitsPerBlock': None, 'additionalIncluded': 0.0, 'additionalUsed': 0.0, 'additionalPercentUsed': 0.0, 'additionalRemaining': 0.0, 'billableOverage': 0.0, 'overageCharges': 0.0, 'overageUsed': 0.0, 'currentCreditAmount': 0, 'maxCreditAmount': 0, 'policy': 'unlimited'}]}

robert-alfaro commented 4 years ago

Cool, one more request.. can you screenshot the sensors attributes from states menu is home assistant?

SamMcDowell commented 4 years ago

Here's the states page screenshot for the xfinity usage.

image

-Sam

robert-alfaro commented 4 years ago

Thanks @SamMcDowell , big help!

I'll do my due diligence and test myself..and get this merged soon.

SamMcDowell commented 4 years ago

You bet - appreciate you looking into it. I've been looking for better ways to monitor the Xfinity usage and somewhere along the way got put on unlimited! I do like having the plot show up on my HASS monitoring page - very useful. -Sam

nnhhuu commented 4 years ago

i have tested the unlimited branch, it is working as I expected.

Thank you very much.