myTselection / telenet_telemeter

Telenet Telemeter Home Assistant custom component HACS for Belgian ISP and mobile phone network traffic.
MIT License
28 stars 5 forks source link

Telenet: multiple internet subscriptions (abonnementen) - the data of only 1 subscription is shown #45

Open PVanhevel opened 6 months ago

PVanhevel commented 6 months ago

When one has multiple subscriptions e.g. 1 modem at the main residence and 1 modem at a secondary residence, only the data of 1 internet subscription are available. The data of the mobile services on the other hand, are available for both subscriptions.

myTselection commented 6 months ago

I don't have such account with multiple subscriptions. If you could share the (annonimzed) data shown within the attribute telemeter_json I can take a look to support this.

PVanhevel commented 6 months ago

internetProductDetails = session.productSubscriptions("INTERNET")

internetProductDetails[0] = {'activationDate': 'xxxxxxxxxxxxxx', 'addressId': '9999999999999999999', 'identifier': '**', 'label': 'All-Internet / **', 'locationId': '9999999999999999999', 'status': 'Active', 'productType': 'internet', 'internetType': 'FUP', 'specurl': 'https://api.prd.telenet.be/omapi/public/product/INTF0200', 'id': '9999999999999999999', 'useSpecurl': True, 'hasVoiceMail': False}

internetProductDetails[1] = {'activationDate': 'xxxxxxxxxxxxxx', 'addressId': '9999999999999999999', 'identifier': '**', 'label': 'WIGO Home S / WIGOHOMES_9999999', 'locationId': '9999999999999999999', 'status': 'Active', 'productType': 'bundle', 'internetType': 'CAP', 'bundleIdentifier': 'WIGOHOMES_9999999', 'specurl': 'https://api.prd.telenet.be/omapi/public/product/WIGO0001', 'id': '9999999999999999999', 'useSpecurl': True, 'hasVoiceMail': False, 'bundleType': 'WIGO'}

Only internetProductDetails[0] appears in HA.

PVanhevel commented 6 months ago

planinfo = session.planInfo() list size = 5

planinfo[0] = {'activationDate': 'xxxxxxxxxx ', 'addressId': '99999999999999', 'identifier': '****', 'label': 'All-Internet / ****', 'locationId': '99999999999999999', 'status': 'Active', 'productType': 'internet', 'isDataOnlyPlan': False, 'specurl': 'https://api.prd.telenet.be/omapi/public/product/INTF0200', 'id': '99999999999999', 'useSpecurl': False, 'hasVoiceMail': False, 'hasActiveMyBill': False}

...

planinfo[2] = {'activationDate': xxxxxxxxxxxxx, 'addressId': '999999999999999', 'identifier': 'WIGOHOMES_99999999, 'label': 'WIGO Home S / WIGOHOMES_999999999', 'locationId': '99999999999999999999', 'status': 'Active', 'productType': 'bundle', 'isDataOnlyPlan': False, 'products': [{'identifier': 99999999', 'productType': 'telephone', 'isDataOnlyLine': False}, {'identifier': '**', 'productType': 'internet', 'isDataOnlyLine': False}, {'identifier': 'DTV99999999', 'productType': 'dtv', 'isDataOnlyLine': False}], 'specurl': 'https://api.prd.telenet.be/omapi/public/product/WIGO0001', 'bundleFamily': 'WIGO', 'id': 9999999999999999', 'useSpecurl': False, 'hasVoiceMail': False, 'hasActiveMyBill': False}

...

PVanhevel commented 6 months ago

"If you could share the (anonymized) data shown within the attribute telemeter_json I can take a look to support this."

As there is no sensor for internetProductDetails[1] or planinfo[2], there is no relevant attribute telemeter_json.

PVanhevel commented 1 month ago

planInfo = session.planInfo() planInfo.reverse() productIdentifier = productIdentifiers[1] _telemeter = session.productUsage("internet", productIdentifier, startDate, endDate) print(_telemeter) {'internet': {'category': 'CAP', 'specurl': 'https://api.prd.telenet.be/omapi/public/product/WIGO0001', 'daysUntil': '24', 'validity': '2024-09-03T12:00:00.000Z', 'allocatedUsage': {'units': 200.0, 'usedUnits': 37.86, 'remainingUnits': 162.14, 'unitType': 'GB', 'usedPercentage': '18.00', 'lastUsageDate': '2024-08-10T09:43:00'}, 'extendedUsage': {'eligibleToBuy': True, 'volumeBlocks': '0', 'volume': 0, 'unit': 'GB', 'price': '0.00', 'currency': 'EUR'}, 'totalUsage': {'units': 37.86, 'unitType': 'GB', 'lastUsageDate': '2024-08-10T09:43:00'}, 'peakUsage': {'usedUnits': 0}}}

Actually I am only interested in usedPercentage = int(_telemeter["internet"]["allocatedUsage"]["usedPercentage"][:2]) usedPeriod = int((1 - int(_telemeter["internet"]["daysUntil"]) / 365.25 12) 100)

myTselection commented 1 month ago

I need a generic approach / rule to extract the data: if there are multiple internetProductDetails product types should I use bundle instead of internet?

PVanhevel commented 1 month ago
def productSubscriptions(self, productType):
    response = self.callTelenet(f"https://api.prd.telenet.be/ocapi/public/api/product-service/v1/product-subscriptions? 
            producttypes={productType}", "productSubscriptions")
    # return response.json()
    return response

session = TelenetSession()
session.login(CONF_USERNAME, CONF_PASSWORD)
internetProductDetails = session.productSubscriptions("INTERNET")

[ { "activationDate" : "2023-03-11T00:00", "addressId" : "9999999999999999", "identifier" : "xxxxxx", "label" : "All-Internet / xxxxx", "locationId" : "99999999999", "status" : "Active", "productType" : "internet", "internetType" : "FUP", "specurl" : "https://api.prd.telenet.be/omapi/public/product/INTF0200", "id" : "99999999999", "useSpecurl" : true, "hasVoiceMail" : false }, { "activationDate" : "2020-02-07T00:00", "addressId" : "999999999999", "identifier" : "yyyyyyyy", "label" : "WIGO Home S / WIGOHOMES_44714708", "locationId" : "9999999999", "status" : "Active", "productType" : "bundle", "internetType" : "CAP", "bundleIdentifier" : "WIGOHOMES_999999999", "specurl" : "https://api.prd.telenet.be/omapi/public/product/WIGO0001", "id" : "99999999999", "useSpecurl" : true, "hasVoiceMail" : false, "bundleType" : "WIGO" } ]

I am only interested in the product with "productType" == "bundle".