Skip to content

Commit

Permalink
Merge pull request #7 from ryanmac8/bugfix/fix-single-line-error
Browse files Browse the repository at this point in the history
Bugfix/fix single line error
  • Loading branch information
ryanmac8 authored Dec 23, 2020
2 parents 6ad17a6 + d8d5666 commit e098d6f
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 19 deletions.
1 change: 0 additions & 1 deletion .github/workflows/combined.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
- uses: hacs/action@main
with:
CATEGORY: integration
ignore: "brands"
- uses: "home-assistant/actions/hassfest@master"
- uses: KTibow/ha-blueprint@main
name: CI
Expand Down
Binary file not shown.
38 changes: 22 additions & 16 deletions custom_components/mintmobile/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,28 @@ def get_family_members(self):
auth=BearerAuth(str(self.token)),
)
response = r.json()
for activeMembers in response["activeMembers"]:
self.family_members.append(activeMembers["id"])
self.info[activeMembers["id"]] = {}
# self.info[activeMembers['id']]={"phone_number":activeMembers['msisdn'],"line_name":activeMembers['nickName']}
self.info[activeMembers["id"]]["phone_number"] = activeMembers["msisdn"]
self.info[activeMembers["id"]]["line_name"] = activeMembers["nickName"]
self.info[activeMembers["id"]]["endOfCycle"] = self.epoch_days_remaining(
activeMembers["currentPlan"]["rechargeDate"]
)
self.info[activeMembers["id"]]["months"] = activeMembers["currentPlan"][
"duration"
]
self.info[activeMembers["id"]]["exp"] = self.epoch_days_remaining(
activeMembers["nextPlan"]["renewalDate"]
)
self.family_data_remaining()

# Uncomment line below to test integration that doesn't have family lines.
# response={'hasAvailableLine': True, 'hasActionRequired': False, 'activeMembers': [], 'requests': []}
if response["activeMembers"]:
for activeMembers in response["activeMembers"]:
self.family_members.append(activeMembers["id"])
self.info[activeMembers["id"]] = {}
# self.info[activeMembers['id']]={"phone_number":activeMembers['msisdn'],"line_name":activeMembers['nickName']}
self.info[activeMembers["id"]]["phone_number"] = activeMembers["msisdn"]
self.info[activeMembers["id"]]["line_name"] = activeMembers["nickName"]
self.info[activeMembers["id"]][
"endOfCycle"
] = self.epoch_days_remaining(
activeMembers["currentPlan"]["rechargeDate"]
)
self.info[activeMembers["id"]]["months"] = activeMembers["currentPlan"][
"duration"
]
self.info[activeMembers["id"]]["exp"] = self.epoch_days_remaining(
activeMembers["nextPlan"]["renewalDate"]
)
self.family_data_remaining()

def family_data_remaining(self):
for member in self.family_members:
Expand Down
54 changes: 54 additions & 0 deletions custom_components/mintmobile/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,60 @@ def async_get_options_flow(config_entry):
return OptionsFlowHandler(config_entry)


class OptionsFlowHandler(config_entries.OptionsFlow):
def __init__(self, config_entry):
"""Initialize HACS options flow."""
self.config_entry = config_entry
self.options = dict(config_entry.options)
self._errors = {}
self._data = {}

async def async_step_init(self, user_input=None):
return await self.async_step_user()

async def async_step_user(self, user_input=None):
if user_input is not None:
self._data = user_input
return await self._update_options()

data_schema = OrderedDict()
data_schema[
vol.Required("username", default=self.config_entry.data.get(CONF_USERNAME))
] = str
data_schema[vol.Required("password", default="")] = str

return self.async_show_form(
step_id="user",
data_schema=vol.Schema(data_schema),
errors=self._errors,
)

async def _update_options(self):
"""Update config entry options."""
valid = await self._test_credentials(
self._data[CONF_USERNAME],
self._data[CONF_PASSWORD],
)
if valid:
return self.async_create_entry(
title=self.config_entry.data.get(CONF_USERNAME), data=self._data
)
else:
self._errors["base"] = "invalid_credentials"
return await self.async_step_user()

async def _test_credentials(self, username, password):
"""Return true if credentials is valid."""
mm = MintMobile(username, password)
return await self.hass.async_add_executor_job(mm.login)

# Options Flow
@staticmethod
@callback
def async_get_options_flow(config_entry):
return OptionsFlowHandler(config_entry)


class OptionsFlowHandler(config_entries.OptionsFlow):
def __init__(self, config_entry):
"""Initialize HACS options flow."""
Expand Down
5 changes: 3 additions & 2 deletions custom_components/mintmobile/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"name": "Mint Mobile",
"documentation": "https://github.com/ryanmac8/HA-Mint-Mobile",
"codeowners": ["@ryanmac8"],
"requirements": ["requests==2.22.0"],
"config_flow": true
"requirements": ["requests>=2.22.0"],
"config_flow": true,
"issue_tracker": "https://github.com/ryanmac8/HA-Mint-Mobile/issues"
}
22 changes: 22 additions & 0 deletions custom_components/mintmobile/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pprint

from api import MintMobile

pp = pprint.PrettyPrinter(indent=4)

username = input("Phone Number: ")
password = input("Enter Your Password: ")


mm = MintMobile(username, password)
print("Logging Into Mint Mobile.")
if mm.login():
print("Login Successful")
else:
print("Login Unsuccessful")

print("Printing All Mint Mobiles Found")
pp.pprint(mm.lines())

print("Printing Data From All Lines")
pp.pprint(mm.get_all_data_remaining())

0 comments on commit e098d6f

Please sign in to comment.