Skip to content

Commit c70976f

Browse files
committed
v2.0.2
添加自定义数据请求时间间隔 分钟预报没有数据返回的处理
1 parent b8925ac commit c70976f

File tree

8 files changed

+94
-117
lines changed

8 files changed

+94
-117
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
+ 天气预报和小时预报不再写入状态机,[前端卡片](https://github.com/fineemb/lovelace-colorfulclouds-weather-card)将会同步更新
5757
+ ### v2.0.1
5858
+ 修复因彩云api返回数据不完整导致的崩溃 [#53](https://github.com/fineemb/Colorfulclouds-weather/issues/53)
59+
+ ### v2.0.2
60+
+ 彩云api不返回分钟预报数据 [#54](https://github.com/fineemb/Colorfulclouds-weather/issues/54)
61+
+ 添加自定义api请求间隔时间(默认是10分钟)
5962

6063
## 安装配置
6164

custom_components/colorfulclouds/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
CONF_DAILYSTEPS,
1919
CONF_HOURLYSTEPS,
2020
CONF_STARTTIME,
21+
CONF_INTERVAL,
2122
COORDINATOR,
2223
DOMAIN,
2324
UNDO_UPDATE_LISTENER,
@@ -50,6 +51,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
5051
hourlysteps = config_entry.options.get(CONF_HOURLYSTEPS, 24)
5152
alert = config_entry.options.get(CONF_ALERT, True)
5253
starttime = config_entry.options.get(CONF_STARTTIME, 0)
54+
interval = config_entry.options.get(CONF_INTERVAL, 10)
5355
# _LOGGER.debug("Using location_key: %s, get forecast: %s", location_key, api_version)
5456
websession = async_get_clientsession(hass)
5557
coordinator = ColorfulcloudsDataUpdateCoordinator(
@@ -64,6 +66,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
6466
hourlysteps,
6567
alert,
6668
starttime,
69+
interval,
6770
)
6871
await coordinator.async_config_entry_first_refresh()
6972
undo_listener = config_entry.add_update_listener(update_listener)

custom_components/colorfulclouds/colorfulclouds.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ColorfulcloudsDataUpdateCoordinator(DataUpdateCoordinator):
1919
def __init__(
2020
self,
2121
hass,
22-
session,
22+
websession,
2323
api_key,
2424
api_version,
2525
location_key,
@@ -29,13 +29,15 @@ def __init__(
2929
hourlysteps: int,
3030
alert: bool,
3131
starttime: int,
32+
interval: int,
3233
):
3334
"""Initialize."""
3435
self.location_key = location_key
3536
self.longitude = longitude
3637
self.latitude = latitude
3738
self.dailysteps = dailysteps
3839
self.alert = alert
40+
self.interval = interval
3941
self.hourlysteps = hourlysteps
4042
self.api_version = api_version
4143
self.api_key = api_key
@@ -46,7 +48,7 @@ def __init__(
4648
else:
4749
self.is_metric = "imperial"
4850

49-
update_interval = datetime.timedelta(minutes=6)
51+
update_interval = datetime.timedelta(minutes=self.interval)
5052
_LOGGER.debug("Data will be update every %s", update_interval)
5153

5254
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=update_interval)

custom_components/colorfulclouds/config_flow.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@
1515
from homeassistant.exceptions import HomeAssistantError
1616
import homeassistant.helpers.config_validation as cv
1717

18-
from .const import CONF_ALERT, CONF_DAILYSTEPS, CONF_HOURLYSTEPS, CONF_STARTTIME, DOMAIN
18+
from .const import (
19+
CONF_ALERT,
20+
CONF_DAILYSTEPS,
21+
CONF_HOURLYSTEPS,
22+
CONF_STARTTIME,
23+
CONF_INTERVAL,
24+
DOMAIN,
25+
)
1926

2027
_LOGGER = logging.getLogger(__name__)
2128

@@ -143,6 +150,10 @@ async def async_step_user(self, user_input=None):
143150
CONF_DAILYSTEPS,
144151
default=self.config_entry.options.get(CONF_DAILYSTEPS, 5),
145152
): vol.All(vol.Coerce(int), vol.Range(min=5, max=15)),
153+
vol.Optional(
154+
CONF_INTERVAL,
155+
default=self.config_entry.options.get(CONF_INTERVAL, 5),
156+
): vol.All(vol.Coerce(int), vol.Range(min=1)),
146157
vol.Optional(
147158
CONF_HOURLYSTEPS,
148159
default=self.config_entry.options.get(CONF_HOURLYSTEPS, 24),

custom_components/colorfulclouds/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
CONF_HOURLYSTEPS = "hourlysteps"
77
CONF_DAILYSTEPS = "dailysteps"
88
CONF_STARTTIME = "starttime"
9+
CONF_INTERVAL = "interval"
910

1011
COORDINATOR = "coordinator"
1112

custom_components/colorfulclouds/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"homekit": {},
1010
"iot_class": "cloud_polling",
1111
"requirements": [],
12-
"version": "2.0.0",
12+
"version": "2.0.2",
1313
"ssdp": [],
1414
"zeroconf": []
1515
}

custom_components/colorfulclouds/translations/zh-Hans.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"dailysteps": "天级预报(5-15)",
3030
"hourlysteps": "小时级预报(24-360)",
3131
"alert": "极端天气预警",
32-
"starttime": "预报起始时间,-1 是昨天,-2 是前天"
32+
"starttime": "预报起始时间,-1 是昨天,-2 是前天",
33+
"interval": "定时刷新数据间隔(分钟)"
3334
},
3435
"description": "设置你需要获取预报数据的天数,以及极端天气预警数据"
3536
}

0 commit comments

Comments
 (0)