1 """The Smappee integration."""
3 from pysmappee
import Smappee, helper, mqtt
4 import voluptuous
as vol
18 from .
import api, config_flow
23 MIN_TIME_BETWEEN_UPDATES,
28 type SmappeeConfigEntry = ConfigEntry[SmappeeBase]
30 CONFIG_SCHEMA = vol.Schema(
34 vol.Required(CONF_CLIENT_ID): cv.string,
35 vol.Required(CONF_CLIENT_SECRET): cv.string,
39 extra=vol.ALLOW_EXTRA,
43 async
def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
44 """Set up the Smappee component."""
45 hass.data[DOMAIN] = {}
47 if DOMAIN
not in config:
50 client_id = config[DOMAIN][CONF_CLIENT_ID]
51 hass.data[DOMAIN][client_id] = {}
54 platform =
"PRODUCTION"
55 if client_id ==
"homeassistant_f2":
56 platform =
"ACCEPTANCE"
57 elif client_id ==
"homeassistant_f3":
58 platform =
"DEVELOPMENT"
60 hass.data[DOMAIN][CONF_PLATFORM] = platform
62 config_flow.SmappeeFlowHandler.async_register_implementation(
64 config_entry_oauth2_flow.LocalOAuth2Implementation(
67 config[DOMAIN][CONF_CLIENT_ID],
68 config[DOMAIN][CONF_CLIENT_SECRET],
69 AUTHORIZE_URL[platform],
78 """Set up Smappee from a zeroconf or config entry."""
79 if CONF_IP_ADDRESS
in entry.data:
80 if helper.is_smappee_genius(entry.data[CONF_SERIALNUMBER]):
82 smappee_mqtt = mqtt.SmappeeLocalMqtt(
83 serial_number=entry.data[CONF_SERIALNUMBER]
85 await hass.async_add_executor_job(smappee_mqtt.start_and_wait_for_config)
87 api=smappee_mqtt, serialnumber=entry.data[CONF_SERIALNUMBER]
91 smappee_api = api.api.SmappeeLocalApi(ip=entry.data[CONF_IP_ADDRESS])
93 api=smappee_api, serialnumber=entry.data[CONF_SERIALNUMBER]
95 await hass.async_add_executor_job(smappee.load_local_service_location)
98 await config_entry_oauth2_flow.async_get_config_entry_implementation(
105 smappee = Smappee(api=smappee_api)
106 await hass.async_add_executor_job(smappee.load_service_locations)
110 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
116 """Unload a config entry."""
117 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
121 """An object to hold the PySmappee instance."""
123 def __init__(self, hass: HomeAssistant, smappee: Smappee) ->
None:
124 """Initialize the Smappee API wrapper class."""
128 @Throttle(MIN_TIME_BETWEEN_UPDATES)
130 """Update all Smappee trends and appliance states."""
131 await self.
hasshass.async_add_executor_job(
132 self.
smappeesmappee.update_trends_and_appliance_states
None __init__(self, HomeAssistant hass, Smappee smappee)
bool async_setup_entry(HomeAssistant hass, SmappeeConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, SmappeeConfigEntry entry)
bool async_setup(HomeAssistant hass, ConfigType config)