コード例 #1
0
        public async Task <IEnumerable <EnergySiteProduct> > fetchProducts(TeslaAuthToken authToken)
        {
            UriBuilder uri = OwnerApiClientImpl.apiRoot
                             .WithPathSegment("products");

            try {
                HttpRequestMessage request = OwnerApiClientImpl.createRequest(HttpMethod.Get, uri, authToken);
                using HttpResponseMessage response = await httpClient.SendAsync(request);

                var products = await readContentAsJson <ProductsResponse>(response);

                return(products.response);
            } catch (HttpRequestException e) {
                throw new TeslaException("Failed to fetch site ID of the solar panels at the house", e);
            }
        }
コード例 #2
0
        public async Task <HistoricalCalendarDataResponse> fetchHistoricalCalendarData(long siteId,
                                                                                       LocalDate dayInDesiredMonth, DateTimeZone reportTimeZone, TeslaAuthToken authToken)
        {
            ZonedDateTime endOfMonth = getEndOfMonth(dayInDesiredMonth, reportTimeZone);
            UriBuilder    uri        = OwnerApiClientImpl.apiRoot
                                       .WithPathSegment("energy_sites")
                                       .WithPathSegment(siteId.ToString())
                                       .WithPathSegment("calendar_history")
                                       .WithParameter("kind", "energy")
                                       .WithParameter("period", "month")
                                       .WithParameter("end_date", ISO_8601_DATETIME_MILLIS_ZONE.Format(endOfMonth));

            try {
                HttpRequestMessage request = OwnerApiClientImpl.createRequest(HttpMethod.Get, uri, authToken);
                using HttpResponseMessage response = await httpClient.SendAsync(request);

                var historicalCalendarData = await readContentAsJson <HistoricalCalendarData>(response);

                return(historicalCalendarData.response);
            } catch (HttpRequestException e) {
                throw new TeslaException($"Failed to get historical solar calendar data for the month ending on {endOfMonth}", e);
            }
        }