Skip to main content
Version: v1.0

WEATHER

Creating Sensors​

const weather = hmSensor.createSensor(hmSensor.id.WEATHER)

WEATHER instance​

weather.getForecastWeather()​

Type​

() => ForecastWeather

ForecastWeather: object​

PropertiesDescriptionType
cityNameCity Namestring
forecastDataWeather DataForecastData
tideDataSunrise/Sunset DataTideData

ForecastData: object​

PropertiesDescriptionType
dataArray of weather data, index 0 position for the dayArray<ForecastDataItem>
countLength of the ForecastData arraynumber

ForecastDataItem: object​

PropertiesDescriptionType
highHighest temperaturenumber
lowLowest temperaturenumber
indexWeather index, values are detailed in the table belownumber
index valueDescription
0Cloudy
1Showers
2Snow Showers
3Sunny
4Overcast
5Light Rain
6Light Snow
7Moderate Rain
8Moderate Snow
9Heavy Snow
10Heavy Rain
11Sandstorm
12Rain and Snow
13Fog
14Hazy
15T-Storms
16Snowstorm
17Floating dust
18Very Heavy Rainstorm
19Rain and Hail
20T-Storms and Hail
21Heavy Rainstorm
22Dust
23Heavy sand storm
24Rainstorm
25Unknown
26Cloudy Nighttime
27Showers Nighttime
28Sunny Nighttime

TideData: object​

PropertiesDescriptionType
dataTideData array, Index 0 Position represents the dayArray<TideDataItem>
countLength of the TideData arraynumber

TideDataItem: object​

PropertiesDescriptionType
sunriseSunrise dataSunrise
sunsetSunset dataSunset

Sunrise: object​

PropertiesDescriptionType
hourHournumber
minuteMinutenumber

Sunset: object​

PropertiesDescriptionType
hourHournumber
minuteMinutenumber

Code example​

class TextByLine {
constructor(params) {
const { text = '', y = undefined, line = 0 } = params

this.text = text
this.y = y
this.line = line
this.y_computed = Number.isInteger(this.y) ? this.y : px(this.line * 60 + 120)
}

render() {
return hmUI.createWidget(hmUI.widget.TEXT, {
x: px(0),
y: this.y_computed,
w: px(480),
h: px(46),
color: 0xffffff,
text_size: px(20),
align_h: hmUI.align.CENTER_H,
align_v: hmUI.align.CENTER_V,
text_style: hmUI.text_style.NONE,
text: this.text
})
}
}

Page({
build() {
const weather = hmSensor.createSensor(hmSensor.id.WEATHER)
const weatherData = weather.getForecastWeather()
const { forecastData, tideData } = weatherData

new TextByLine({
text: `cityName:${weatherData.cityName}`,
line: 0
}).render()

new TextByLine({
text: `forecastCount:${forecastData.count};tideCount:${tideData.count}`,
line: 1
}).render()

for (let i = 0; i < forecastData.count; i++) {
const { index, high, low } = forecastData.data[i]

new TextByLine({
text: `index:${index};high:${high};low:${low}`,
line: 2 + i
}).render()
}

for (let i = 0; i < tideData.count; i++) {
const {
sunrise: { hour: sunriseHour, minute: sunriseMinute },
sunset: { hour: sunsetHour, minute: sunsetMinute }
} = tideData.data[i]

new TextByLine({
text: `sunrise:${sunriseHour}:${sunriseMinute};sunset:${sunsetHour}:${sunsetMinute}`,
line: 2 + i + forecastData.count
}).render()
}
}
})