Kajkac / ZTE-MC-Home-assistant-repo

ZTE MC801A, MC888, MC889 Home assistant Custom integration
GNU General Public License v3.0
11 stars 2 forks source link

Control network mode by homeassistant #5

Closed Shariner closed 2 months ago

Shariner commented 2 months ago

Tested on MC888: When the switch is selected, the data goes offline automatically (you don't have to create an automation for it, so its indeed a better solution than the webpage where you need to disconnect manually before changing data mode). Then the data status is changed and data mode is activated for reconnection automatically.

I just programmed the "5G NSA" (called LTE AND 5G) and "5G SA" (called 5G only) switches. I will add the other switches too, but maybe uncommented.

I will create a push in the next days, but here again: I don't know if these commands work on the other models.

added to mc.py:


    def setdata_5G_SA(self):
        cookie = self.getCookie(password=self.password, LD=self.get_LD())
        AD = self.get_AD()
        header = {"Referer": self.referer, "Cookie": cookie}
        payload = f'isTest=false&goformId=Only_5G&AD=' + AD
        payload = f'isTest=false&goformId=SET_BEARER_PREFERENCE&BearerPreference=Only_5G&AD=' + AD
        print(payload)
        r = s.post(self.referer + "goform/goform_set_cmd_process", headers=header, data=payload, verify=False)
        return r.status_code

    def setdata_5G_NSA(self):
        cookie = self.getCookie(password=self.password, LD=self.get_LD())
        AD = self.get_AD()
        header = {"Referer": self.referer, "Cookie": cookie}
        payload = f'isTest=false&goformId=SET_BEARER_PREFERENCE&BearerPreference=LTE_AND_5G&AD=' + AD
        print(payload)
        r = s.post(self.referer + "goform/goform_set_cmd_process", headers=header, data=payload, verify=False)
        return r.status_code

edited in switch.py:

async_add_entities([
    ZTERouterSwitch(main_coordinator, ip_entry, password_entry, router_type, "Reboot Router", "4"),
    ZTERouterSwitch(main_coordinator, ip_entry, password_entry, router_type, "Delete All SMS", "5"),
    ZTERouterSwitch(main_coordinator, ip_entry, password_entry, router_type, "Send SMS 50GB", "8"),
    ZTERouterSwitch(main_coordinator, ip_entry, password_entry, router_type, "Connect Data", "9"),
    ZTERouterSwitch(main_coordinator, ip_entry, password_entry, router_type, "Disconnect Data", "10"),
    ZTERouterSwitch(main_coordinator, ip_entry, password_entry, router_type, "Set 5G SA", "11"),
    ZTERouterSwitch(main_coordinator, ip_entry, password_entry, router_type, "Set 5G NSA", "12")
], False)

Will rewrite this to use a input_select entidy

Shariner commented 2 months ago

First release in https://github.com/Kajkac/ZTE-MC-Home-assistant-repo/pull/6/commits/dfebd0a038bea766ca36917ed3b344de8d8e610e