예제 #1
0
def setup_api(data, requests_mock):
    """Set up API with fake data."""
    resource = f"http://localhost{google_wifi.ENDPOINT}"
    now = datetime(1970, month=1, day=1)
    sensor_dict = {}
    with patch("homeassistant.util.dt.now", return_value=now):
        requests_mock.get(resource, text=data, status_code=200)
        conditions = google_wifi.MONITORED_CONDITIONS.keys()
        api = google_wifi.GoogleWifiAPI("localhost", conditions)
    for condition, cond_list in google_wifi.MONITORED_CONDITIONS.items():
        sensor_dict[condition] = {
            "sensor": google_wifi.GoogleWifiSensor(api, NAME, condition),
            "name": f"{NAME}_{condition}",
            "units": cond_list[1],
            "icon": cond_list[2],
        }
    return api, sensor_dict
예제 #2
0
def setup_api(hass, data, requests_mock):
    """Set up API with fake data."""
    resource = f"http://localhost{google_wifi.ENDPOINT}"
    now = datetime(1970, month=1, day=1)
    sensor_dict = {}
    with patch("homeassistant.util.dt.now", return_value=now):
        requests_mock.get(resource, text=data, status_code=200)
        conditions = google_wifi.SENSOR_KEYS
        api = google_wifi.GoogleWifiAPI("localhost", conditions)
    for desc in google_wifi.SENSOR_TYPES:
        sensor_dict[desc.key] = {
            "sensor": google_wifi.GoogleWifiSensor(api, NAME, desc),
            "name": f"{NAME}_{desc.key}",
            "units": desc.native_unit_of_measurement,
            "icon": desc.icon,
        }
    for name in sensor_dict:
        sensor = sensor_dict[name]["sensor"]
        sensor.hass = hass

    return api, sensor_dict
예제 #3
0
 def setup_api(self, data, mock_req):
     """Set up API with fake data."""
     resource = f"http://localhost{google_wifi.ENDPOINT}"
     now = datetime(1970, month=1, day=1)
     with patch("homeassistant.util.dt.now", return_value=now):
         mock_req.get(resource, text=data, status_code=200)
         conditions = google_wifi.MONITORED_CONDITIONS.keys()
         self.api = google_wifi.GoogleWifiAPI("localhost", conditions)
     self.name = NAME
     self.sensor_dict = dict()
     for condition, cond_list in google_wifi.MONITORED_CONDITIONS.items():
         sensor = google_wifi.GoogleWifiSensor(self.api, self.name, condition)
         name = f"{self.name}_{condition}"
         units = cond_list[1]
         icon = cond_list[2]
         self.sensor_dict[condition] = {
             "sensor": sensor,
             "name": name,
             "units": units,
             "icon": icon,
         }
예제 #4
0
 def setup_api(self, data, mock_req):
     """Set up API with fake data."""
     resource = '{}{}{}'.format('http://', 'localhost',
                                google_wifi.ENDPOINT)
     now = datetime(1970, month=1, day=1)
     with patch('homeassistant.util.dt.now', return_value=now):
         mock_req.get(resource, text=data, status_code=200)
         conditions = google_wifi.MONITORED_CONDITIONS.keys()
         self.api = google_wifi.GoogleWifiAPI("localhost", conditions)
     self.name = NAME
     self.sensor_dict = dict()
     for condition, cond_list in google_wifi.MONITORED_CONDITIONS.items():
         sensor = google_wifi.GoogleWifiSensor(self.api, self.name,
                                               condition)
         name = '{}_{}'.format(self.name, condition)
         units = cond_list[1]
         icon = cond_list[2]
         self.sensor_dict[condition] = {
             'sensor': sensor,
             'name': name,
             'units': units,
             'icon': icon
         }