Skip to content

Commit

Permalink
Extend condition model
Browse files Browse the repository at this point in the history
Refs: #16
  • Loading branch information
orontee committed Aug 30, 2023
1 parent cdc024f commit dde397b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,13 @@ enum Weather {

struct Condition {
std::time_t date{0};
std::time_t sunrise{0};
std::time_t sunset{0};
long double temperature;
long double felt_temperature;
int pressure;
int humidity;
long double uv_index;
long double wind_speed;
Weather weather{CLEAR_SKY};
std::string weather_description;
Expand Down
8 changes: 6 additions & 2 deletions src/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,17 @@ class Service {

static Condition extract_condition(const Json::Value &value) {
const auto date = static_cast<time_t>(value.get("dt", 0).asInt());
const auto sunrise = static_cast<time_t>(value.get("sunrise", 0).asInt());
const auto sunset = static_cast<time_t>(value.get("sunset", 0).asInt());
const auto temperature = value.get("temp", NAN).asDouble();
const auto felt_temperature = value.get("feels_like", NAN).asDouble();
const auto pressure = value.get("pressure", NAN).asInt();
const auto humidity = value.get("humidity", NAN).asInt();
const auto uv_index = value.get("uv_index", NAN).asDouble();
const auto wind_speed = value.get("wind_speed", NAN).asDouble();

Condition condition{date, temperature, felt_temperature, humidity,
wind_speed};
Condition condition{date, sunrise, sunset, temperature, felt_temperature,
pressure, humidity, uv_index, wind_speed};

if (value.isMember("weather") and value["weather"].isArray() and
value["weather"].isValidIndex(0)) {
Expand Down

0 comments on commit dde397b

Please sign in to comment.