Skip to main content

TSWeather Module

The TSWeather module provides comprehensive weather information management for TopStepComKit devices. It enables you to fetch current weather conditions, manage weather data synchronization, and control weather display settings. The module supports detailed weather parameters including temperature, wind conditions, humidity, UV index, and multi-day/hourly forecasts.

Prerequisites

  • TopStepComKit framework version 1.0 or later
  • Connected and authenticated device via TSDeviceManager
  • Weather interface implementation conforming to TSWeatherInterface protocol
  • For weather data push operations: device must be in connected state

Data Models

TopStepWeather

Complete weather information model for a location.

PropertyTypeDescription
timestampNSTimeIntervalUnix timestamp when weather information was recorded
updateTimestampNSTimeIntervalUnix timestamp when weather information was last updated
sunriseTimeNSTimeIntervalUnix timestamp representing sunrise time (0 if unavailable)
sunsetTimeNSTimeIntervalUnix timestamp representing sunset time (0 if unavailable)
cityTSWeatherCity *City information for the weather report
dayCodeTSWeatherCodeModel *Daytime weather code and description
nightCodeTSWeatherCodeModel *Nighttime weather code and description (optional)
minTemperatureSInt8Minimum temperature in Celsius
maxTemperatureSInt8Maximum temperature in Celsius
curTemperatureSInt8Current temperature in Celsius
airpressureNSIntegerAtmospheric pressure in hPa
qualityNSIntegerAir quality index (0: Excellent, 1: Good, 2: Light, 3: Moderate, 4: Heavy, 5: Severe)
humidityNSIntegerRelative humidity percentage (0-100)
uvIndexNSIntegerUV radiation intensity (0: None, 1-2: Very Low, 3-4: Low, 5-6: Moderate, 7-8: High, 9-10: Very High, 11: Extreme)
windAngleCGFloatWind direction in degrees (0-359)
windScaleNSIntegerWind scale level (0-18)
windSpeedCGFloatWind speed in m/s
visibilityCGFloatVisibility in meters
futhureSevenDaysNSArray<TSWeatherDay *> *Seven-day forecast array ordered by date
futhure24HoursNSArray<TSWeatherHour *> *24-hour forecast array ordered by time

TSWeatherCity

City model for weather information.

PropertyTypeDescription
cityNameNSString *City name (required)
cityCodeNSString *City unique identifier code (optional)
latitudedoubleCity center latitude in decimal degrees (-90.0 to 90.0)
longitudedoubleCity center longitude in decimal degrees (-180.0 to 180.0)
provinceNameNSString *Province/state name (optional)
countryNameNSString *Country name (optional)

TSWeatherDay

Daily weather information model.

PropertyTypeDescription
timestampNSTimeIntervalUnix timestamp of weather information
dayCodeTSWeatherCodeModel *Daytime weather code
nightCodeTSWeatherCodeModel *Nighttime weather code (optional)
curTemperatureSInt8Current temperature in Celsius
minTemperatureSInt8Minimum temperature in Celsius
maxTemperatureSInt8Maximum temperature in Celsius
airpressureNSIntegerAtmospheric pressure in hPa
windScaleUInt8Wind scale level (0-18)
windAngleNSIntegerWind direction in degrees (0-359)
windSpeedUInt8Wind speed in m/s
humidityUInt8Relative humidity percentage (0-100)
uvIndexUInt8UV radiation intensity index
visibilityCGFloatVisibility in meters

TSWeatherHour

Hourly weather information model.

PropertyTypeDescription
timestampNSTimeIntervalUnix timestamp of weather information
weatherCodeTSWeatherCodeModel *Weather code for the hour
temperatureSInt8Temperature in Celsius
windScaleNSIntegerWind scale level (0-18)
uvIndexNSIntegerUV radiation intensity index
visibilityNSIntegerVisibility in meters
humidityNSIntegerRelative humidity percentage (0-100)

TSWeatherCodeModel

Weather code model representing weather conditions.

PropertyTypeDescription
codeTSWeatherCodeWeather code enumeration value
nameNSString *Text description of weather condition

Enumerations

TSWeatherCode

Weather condition codes based on Yahoo Weather standards.

CodeValueDescription
TSWeatherCodeUnknown-1Unknown weather
TSWeatherCodeTornado0Tornado
TSWeatherCodeTropicalStorm1Tropical Storm
TSWeatherCodeHurricane2Hurricane
TSWeatherCodeStrongStorms3Strong Storms
TSWeatherCodeThunderstorms4Thunderstorms
TSWeatherCodeRainSnow5Rain and Snow
TSWeatherCodeRainSleet6Rain and Sleet
TSWeatherCodeWintryMix7Wintry Mix
TSWeatherCodeFreezingDrizzle8Freezing Drizzle
TSWeatherCodeDrizzle9Drizzle
TSWeatherCodeFreezingRain10Freezing Rain
TSWeatherCodeShowers11Showers
TSWeatherCodeRain12Rain
TSWeatherCodeFlurries13Flurries
TSWeatherCodeSnowShowers14Snow Showers
TSWeatherCodeBlowingSnow15Blowing/Drifting Snow
TSWeatherCodeSnow16Snow
TSWeatherCodeHail17Hail
TSWeatherCodeSleet18Sleet
TSWeatherCodeDustSandstorm19Blowing Dust/Sandstorm
TSWeatherCodeFoggy20Foggy
TSWeatherCodeHaze21Haze
TSWeatherCodeSmoke22Smoke
TSWeatherCodeBreezy23Breezy
TSWeatherCodeWindy24Windy
TSWeatherCodeFrigidIceCrystals25Frigid/Ice Crystals
TSWeatherCodeOvercast26Overcast
TSWeatherCodeMostlyCloudyNight27Mostly Cloudy (night)
TSWeatherCodeMostlyCloudyDay28Mostly Cloudy (day)
TSWeatherCodePartlyCloudyNight29Partly Cloudy (night)
TSWeatherCodePartlyCloudyDay30Partly Cloudy (day)
TSWeatherCodeClearNight31Clear Night
TSWeatherCodeSunnyDay32Sunny Day
TSWeatherCodeFairNight33Fair/Mostly Clear (night)
TSWeatherCodeFairDay34Fair/Mostly Sunny (day)
TSWeatherCodeMixedRainHail35Mixed Rain and Hail
TSWeatherCodeHot36Hot
TSWeatherCodeIsolatedThunderstorms37Isolated Thunderstorms
TSWeatherCodeScatteredStormDay38Scattered Thunderstorms (day)
TSWeatherCodeScatteredShowersDay39Scattered Showers (day)
TSWeatherCodeHeavyRain40Heavy Rain
TSWeatherCodeScatteredSnowDay41Scattered Snow Showers (day)
TSWeatherCodeHeavySnow42Heavy Snow
TSWeatherCodeBlizzard43Blizzard
TSWeatherCodeNotAvailable44Not Available
TSWeatherCodeScatteredShowersNight45Scattered Showers (night)
TSWeatherCodeScatteredSnowNight46Scattered Snow Showers (night)
TSWeatherCodeScatteredStormNight47Scattered Thunderstorms (night)

Callback Types

TSCompletionBlock

typedef void (^TSCompletionBlock)(BOOL success, NSError *_Nullable error);

Completion callback for set operations.

ParameterTypeDescription
successBOOLOperation success status
errorNSError *Error object (nil if successful)

API Reference

Fetch current weather information

Retrieves the current weather information from the device, including current conditions, daily forecast, and hourly forecast.

- (void)fetchWeatherWithCompletion:(void (^)(TopStepWeather *_Nullable weather, NSError *_Nullable error))completion;
ParameterTypeDescription
completionvoid (^)(TopStepWeather *, NSError *)Callback block with weather data or error

Code Example:

id<TSWeatherInterface> weatherInterface = [TSWeatherInterface sharedInstance];

[weatherInterface fetchWeatherWithCompletion:^(TopStepWeather *weather, NSError *error) {
if (error) {
TSLog(@"Failed to fetch weather: %@", error.localizedDescription);
return;
}

TSLog(@"Current temperature: %d°C", weather.curTemperature);
TSLog(@"City: %@", weather.city.cityName);
TSLog(@"Weather condition: %@", weather.dayCode.name);
TSLog(@"Min/Max: %d/%d°C", weather.minTemperature, weather.maxTemperature);
TSLog(@"Humidity: %ld%%", (long)weather.humidity);
TSLog(@"Wind speed: %.1f m/s", weather.windSpeed);
TSLog(@"7-day forecast available: %lu days", (unsigned long)weather.futhureSevenDays.count);
TSLog(@"24-hour forecast available: %lu hours", (unsigned long)weather.futhure24Hours.count);
}];

Push weather information to device

Synchronizes weather information to the device for display.

- (void)pushWeather:(TopStepWeather *)weather completion:(TSCompletionBlock)completion;
ParameterTypeDescription
weatherTopStepWeather *Weather information model to synchronize
completionTSCompletionBlockCallback indicating success or failure

Code Example:

// Create weather information
TopStepWeather *weather = [[TopStepWeather alloc] init];
weather.timestamp = [[NSDate date] timeIntervalSince1970];
weather.updateTimestamp = weather.timestamp;
weather.curTemperature = 22;
weather.minTemperature = 15;
weather.maxTemperature = 28;
weather.humidity = 65;
weather.uvIndex = 3;
weather.windScale = 3;
weather.windSpeed = 2.5;
weather.airpressure = 1013;
weather.quality = 1;
weather.visibility = 10000;

// Create city information
TSWeatherCity *city = [TSWeatherCity cityWithName:@"Beijing"];
city.latitude = 39.9042;
city.longitude = 116.4074;
city.cityCode = @"101010100";
weather.city = city;

// Create weather code
TSWeatherCodeModel *dayCode = [TSWeatherCodeModel weatherCodeWithCode:TSWeatherCodePartlyCloudyDay];
weather.dayCode = dayCode;

// Push to device
id<TSWeatherInterface> weatherInterface = [TSWeatherInterface sharedInstance];
[weatherInterface pushWeather:weather completion:^(BOOL success, NSError *error) {
if (error) {
TSLog(@"Failed to push weather: %@", error.localizedDescription);
return;
}

if (success) {
TSLog(@"Weather synchronized successfully");
}
}];

Enable or disable weather display

Controls whether the device displays weather information.

- (void)setWeatherEnable:(BOOL)enable completion:(TSCompletionBlock)completion;
ParameterTypeDescription
enableBOOLYES to enable weather display, NO to disable
completionTSCompletionBlockCallback indicating success or failure

Code Example:

id<TSWeatherInterface> weatherInterface = [TSWeatherInterface sharedInstance];

// Enable weather display
[weatherInterface setWeatherEnable:YES completion:^(BOOL success, NSError *error) {
if (error) {
TSLog(@"Failed to enable weather: %@", error.localizedDescription);
return;
}

if (success) {
TSLog(@"Weather display enabled");
}
}];

// Disable weather display
[weatherInterface setWeatherEnable:NO completion:^(BOOL success, NSError *error) {
if (error) {
TSLog(@"Failed to disable weather: %@", error.localizedDescription);
return;
}

if (success) {
TSLog(@"Weather display disabled");
}
}];

Fetch weather display status

Retrieves the current weather display enable/disable status from the device.

- (void)fetchWeatherEnableWithCompletion:(void (^)(BOOL enabled, NSError *_Nullable error))completion;
ParameterTypeDescription
completionvoid (^)(BOOL, NSError *)Callback with enable status and error

Code Example:

id<TSWeatherInterface> weatherInterface = [TSWeatherInterface sharedInstance];

[weatherInterface fetchWeatherEnableWithCompletion:^(BOOL enabled, NSError *error) {
if (error) {
TSLog(@"Failed to fetch weather status: %@", error.localizedDescription);
return;
}

if (enabled) {
TSLog(@"Weather display is enabled");
} else {
TSLog(@"Weather display is disabled");
}
}];

Create city model with name

Creates a city model with the required city name.

+ (instancetype)cityWithName:(NSString *)cityName;
ParameterTypeDescription
cityNameNSString *The city name (required)

Code Example:

TSWeatherCity *city = [TSWeatherCity cityWithName:@"Shanghai"];
TSLog(@"Created city: %@", city.cityName);

Create city model with location

Creates a city model with name and geographic coordinates.

+ (instancetype)cityWithName:(NSString *)cityName
latitude:(double)latitude
longitude:(double)longitude;
ParameterTypeDescription
cityNameNSString *The city name (required)
latitudedoubleCity center latitude (-90.0 to 90.0)
longitudedoubleCity center longitude (-180.0 to 180.0)

Code Example:

TSWeatherCity *city = [TSWeatherCity cityWithName:@"New York" 
latitude:40.7128
longitude:-74.0060];
TSLog(@"Created city: %@ at (%f, %f)", city.cityName, city.latitude, city.longitude);

Create weather code model

Creates a weather code model with the specified code.

+ (instancetype)weatherCodeWithCode:(TSWeatherCode)code;
ParameterTypeDescription
codeTSWeatherCodeWeather code enumeration value

Code Example:

TSWeatherCodeModel *code = [TSWeatherCodeModel weatherCodeWithCode:TSWeatherCodeSunnyDay];
TSLog(@"Weather code: %ld, Name: %@", (long)code.code, code.name);

Get weather name for code

Gets the text description for a specific weather code.

+ (NSString *)weatherNameForCode:(TSWeatherCode)code;
ParameterTypeDescription
codeTSWeatherCodeWeather code enumeration value

Code Example:

NSString *weatherName = [TSWeatherCodeModel weatherNameForCode:TSWeatherCodeRain];
TSLog(@"Weather description: %@", weatherName);

Create daily weather model with basic information

Creates a daily weather model with essential weather parameters.

+ (instancetype)modelWithDayCode:(TSWeatherCodeModel *)dayCode
nightCode:(nullable TSWeatherCodeModel *)nightCode
curTemp:(SInt8)curTemp
minTemp:(SInt8)minTemp
maxTemp:(SInt8)maxTemp;
ParameterTypeDescription
dayCodeTSWeatherCodeModel *Daytime weather code
nightCodeTSWeatherCodeModel *Nighttime weather code (optional)
curTempSInt8Current temperature in Celsius
minTempSInt8Minimum temperature in Celsius
maxTempSInt8Maximum temperature in Celsius

Code Example:

TSWeatherCodeModel *dayCode = [TSWeatherCodeModel weatherCodeWithCode:TSWeatherCodeSunnyDay];
TSWeatherCodeModel *nightCode = [TSWeatherCodeModel weatherCodeWithCode:TSWeatherCodeClearNight];

TSWeatherDay *day = [TSWeatherDay modelWithDayCode:dayCode
nightCode:nightCode
curTemp:22
minTemp:15
maxTemp:28];

TSLog(@"Daily weather: %@ / %@, Temp: %d°C", day.dayCode.name, day.nightCode.name, day.curTemperature);

Create daily weather model with complete information

Creates a daily weather model with all weather parameters.

+ (instancetype)modelWithDayCode:(TSWeatherCodeModel *)dayCode
nightCode:(nullable TSWeatherCodeModel *)nightCode
curTemp:(SInt8)curTemp
minTemp:(SInt8)minTemp
maxTemp:(SInt8)maxTemp
airpressure:(NSInteger)airpressure
windScale:(NSInteger)windScale
windAngle:(NSInteger)windAngle
windSpeed:(NSInteger)windSpeed
humidity:(NSInteger)humidity
uvIndex:(NSInteger)uvIndex
visibility:(CGFloat)visibility;
ParameterTypeDescription
dayCodeTSWeatherCodeModel *Daytime weather code
nightCodeTSWeatherCodeModel *Nighttime weather code (optional)
curTempSInt8Current temperature in Celsius
minTempSInt8Minimum temperature in Celsius
maxTempSInt8Maximum temperature in Celsius
airpressureNSIntegerAtmospheric pressure in hPa
windScaleNSIntegerWind scale level (0-18)
windAngleNSIntegerWind direction in degrees
windSpeedNSIntegerWind speed in m/s
humidityNSIntegerRelative humidity percentage
uvIndexNSIntegerUV radiation intensity
visibilityCGFloatVisibility in meters

Code Example:

TSWeatherCodeModel *dayCode = [TSWeatherCodeModel weatherCodeWithCode:TSWeatherCodePartlyCloudyDay];
TSWeatherCodeModel *nightCode = [TSWeatherCodeModel weatherCodeWithCode:TSWeatherCodeClearNight];

TSWeatherDay *day = [TSWeatherDay modelWithDayCode:dayCode
nightCode:nightCode
curTemp:22
minTemp:15
maxTemp:28
airpressure:1013
windScale:3
windAngle:180
windSpeed:2
humidity:65
uvIndex:3
visibility:10000];

TSLog(@"Complete weather data: Pressure=%ld hPa, Wind=%d, Humidity=%ld%%",
(long)day.airpressure, day.windScale, (long)day.humidity);

Create hourly weather model with basic information

Creates an hourly weather model with essential parameters.

+ (instancetype)modelWithDayCode:(TSWeatherCodeModel *)dayCode
temperature:(SInt8)temperature
windScale:(NSInteger)windScale;
ParameterTypeDescription
dayCodeTSWeatherCodeModel *Weather code for the hour
temperatureSInt8Temperature in Celsius
windScaleNSIntegerWind scale level (0-18)

Code Example:

TSWeatherCodeModel *code = [TSWeatherCodeModel weatherCodeWithCode:TSWeatherCodeRain];

TSWeatherHour *hour = [TSWeatherHour modelWithDayCode:code
temperature:18
windScale:4];

TSLog(@"Hourly weather: %@, Temp: %d°C, Wind scale: %ld",
hour.weatherCode.name, hour.temperature, (long)hour.windScale);

Create hourly weather model with complete information

Creates an hourly weather model with all weather parameters.

+ (instancetype)modelWithCode:(TSWeatherCodeModel *)code
temperature:(SInt8)temperature
windScale:(NSInteger)windScale
uvIndex:(NSInteger)uvIndex
visibility:(CGFloat)visibility
humidity:(NSInteger)humidity;
ParameterTypeDescription
codeTSWeatherCodeModel *Weather code
temperatureSInt8Temperature in Celsius
windScaleNSIntegerWind scale level (0-18)
uvIndexNSIntegerUV radiation intensity
visibilityCGFloatVisibility in meters
humidityNSIntegerRelative humidity percentage

Code Example:

TSWeatherCodeModel *code = [TSWeatherCodeModel weatherCodeWithCode:TSWeatherCodePartlyCloudyDay];

TSWeatherHour *hour = [TSWeatherHour modelWithCode:code
temperature:20
windScale:2
uvIndex:4
visibility:8000
humidity:70];

TSLog(@"Hourly details: UV=%ld, Visibility=%dm, Humidity=%ld%%",
(long)hour.uvIndex, (int)hour.visibility, (long)hour.humidity);

Important Notes

  1. Weather Synchronization: The device must be connected and authenticated before pushing weather information using pushWeather:completion:. Connection status should be verified beforehand.

  2. Temperature Unit: All temperature values in the weather models use Celsius (°C). Conversion to Fahrenheit or other units should be done on the client side if needed.

  3. Timestamp Format: Timestamps should be in Unix format (seconds since January 1, 1970 UTC). Use [[NSDate date] timeIntervalSince1970] to generate current timestamp.

  4. Weather Codes: Use the TSWeatherCode enumeration values when setting weather codes. The codes follow Yahoo Weather standards for consistency across platforms.

  5. Array Ordering: The futhureSevenDays array is ordered by date with the first element representing today. Similarly, futhure24Hours is ordered by time with the first element being the current hour.

  6. Optional Properties: The nightCode property in weather models is optional and may be nil if nighttime weather information is not available. Always check for nil before accessing this property.

  7. Enable/Disable Status: Weather display status can be toggled using setWeatherEnable:completion: and verified using fetchWeatherEnableWithCompletion:. A disabled state will prevent the device from displaying any weather information.

  8. City Model Required: The city property in TopStepWeather is required for weather display. At minimum, provide the city name using [TSWeatherCity cityWithName:].

  9. Wind Direction: Wind direction angle uses standard geographic convention: 0/360 = North, 90 = East, 180 = South, 270 = West. Values should be in the range 0-359 degrees.

  10. UV Index Range: UV index values typically range from 0 (no exposure) to 11+ (extreme exposure). Device firmware may limit the range for safety, so validate values before pushing to device.