天气实体
从 homeassistant.components.weather.WeatherEntity 派生 entity platforms。
属性
Properties 应始终只从内存返回信息,而不要执行 I/O(如网络请求)。请实现 update() 或 async_update() 来获取数据。
单位转换
Properties 必须遵循表中各自计量单位所提及的单位。
对于用户,properties 将根据 unit system 进行呈现。这是通过创建 state objects 时自动转换单位来实现的。
对于每个 weather entity,用户还可以选择覆盖 presentation units,即 state objects 中使用的单位。
state 和 condition 的推荐值
以下 weather conditions 已包含在我们的 translation files 中,并会显示相应的 icon。
这意味着 weather platforms 不需要自己支持各种语言。
支持的功能
Supported features 通过使用 WeatherEntityFeature enum 中的值来定义,
并使用按位或(|)运算符组合。
天气预报
Weather platform 可以选项性地提供 weather forecasts。对 weather forecasts 的支持通过设置正确的 supported feature 来指示。Weather forecasts 不属于 entity 的 state,而是通过单独的 API 提供。Consumer(例如 frontend)可以订阅 weather forecast updates。
预报数据
Forecast data 可以是 daily、hourly 或 twice_daily。集成可以提供其中任意一种或全部。
集成应实现下面文档中说明的一个或多个异步方法 async_forecast_daily、async_forecast_hourly 和 async_forecast_twice_daily 来获取 forecast data。
Forecast data 在适用的情况下,需要遵循与 properties 定义相同的计量单位。
获取天气预报的方法
调用这些 methods 以从 api 获取 forecasts。
更新天气预报
强烈建议 weather entity 缓存获取到的 weather forecasts,以避免不必要的 API 访问。
当有新的 weather forecast 可用时,应使 weather forecast cache 失效,并 await WeatherEntity.async_update_listeners 方法,以触发将更新后的 weather forecast 推送到所有 active subscribers。如果有 active listeners,WeatherEntity.async_update_listeners 将调用相应的 async_forecast_xxx methods。如果没有 active listeners,WeatherEntity.async_update_listeners 不会调用任何 async_forecast_xxx methods。

