WIP: Add iCloud devices battery status + services#24053
Conversation
0e4f9a8 to
e001f3a
Compare
e001f3a to
31cb436
Compare
713b140 to
0693c23
Compare
MartinHjelmare
left a comment
There was a problem hiding this comment.
I've made some comments after my first brief read and impressions.
|
|
||
| if self._accountname in _CONFIGURING: | ||
| request_id = _CONFIGURING.pop(self._accountname) | ||
| configurator = self._hass.components.configurator |
There was a problem hiding this comment.
The configurator is deprecated. Please make use of a config flow and config entry instead.
https://developers.home-assistant.io/docs/en/config_entries_index.html
There was a problem hiding this comment.
Yeah, that would be very nice, I thought about that too.
But should I make it in a new PR to be less messy, then rebase this one, or directly here ?
There was a problem hiding this comment.
You can do it in a separate PR if you prefer that. We like small PRs. 👍
There was a problem hiding this comment.
Hi !
I have some problem to initiate the config flow, can you take a look at this commit (d2bf926) to help me a bit ?
I inspired me from AdGuard Home, Hangout, Hue, and HomeKit.
I have to logged error event if I added some at async_setup_entry, async_step_user ...
And nothing came at the integration panel.

You can notice the "Search" label not well placed, but it used to most of the time (Safari 12.1.1)
I think that I am missing a little thing but I don't know what.
Also :
How can I replace self._hass.config.path('icloud') in the config flow as I can't access _hass ?
Thanks.
There was a problem hiding this comment.
hass can be accessed as self.hass in the config flow methods. That is set by the core when instantiating the flow.
If strings are missing in the frontend, that can be due to missing translation file. Run the translation script to generate the default english translation file from the strings.json file that you should create manually in the package:
https://developers.home-assistant.io/docs/en/internationalization_backend_localization.html#translation-strings
https://developers.home-assistant.io/docs/en/internationalization_backend_localization.html#configuration-flow-localization
Also make sure you have registered the config flow class:
https://developers.home-assistant.io/docs/en/data_entry_flow_index.html#flow-handler
There was a problem hiding this comment.
Thanks for the hass
I've created a translation and had registered the config flow here, still nothing.
There was a problem hiding this comment.
Make sure you have activated config flow in manifest.json.
There was a problem hiding this comment.
Same with "config_flow": true, in the manifest
|
|
||
| else: | ||
| _LOGGER.error("No ICLOUDTRACKERS added") | ||
| def setup_scanner(hass, config, see, discovery_info=None): |
There was a problem hiding this comment.
After moving this integration to use config entries, the device tracker platform should subclass the new TrackerEntity class in the device tracker component.
See the gpslogger integration for example:
https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/gpslogger/device_tracker.py
c7e2492 to
9b01408
Compare
d2bf926 to
cad0571
Compare
cad0571 to
0dc0dfa
Compare
0dc0dfa to
384d945
Compare
| accountname = slugify(accountname.partition('@')[0]) | ||
| hass.data[DATA_ICLOUD][accountname].reset_account() | ||
|
|
||
| hass.services.register( |
There was a problem hiding this comment.
Use the home assistant async api in async context. hass.services.async_register
|
|
||
| def icloud_need_trusted_device(self): | ||
| """We need a trusted device.""" | ||
| configurator = self.hass.components.configurator |
There was a problem hiding this comment.
This should be replaced with config flow steps.
| "config": { | ||
| "title": "Apple iCloud", | ||
| "step": { | ||
| "init": { |
There was a problem hiding this comment.
This should be the user step.
| "data": { | ||
| "username": "Username", | ||
| "password": "Password" | ||
| } |
There was a problem hiding this comment.
Make sure that all config flow form items are represented here in the data.
| @@ -0,0 +1,106 @@ | |||
| """Battery state for iCloud devices.""" | |||
There was a problem hiding this comment.
Please don't add new platforms in this PR. Let's do that in subsequent PRs.
There was a problem hiding this comment.
Actually, this PR was originally made to add this platform, but, config flow first !
|
@Quentame are you planning to finish here? |
|
Hi @MartinHjelmare, nope ! 😉 I've actually dev the config flow for iCloud and it's working (and taking care of your comments). I mean kinda since the UI is working, but I can't really add the integration due to iCloud API is not working right now (#24476). So I'm gonna create a new PR, for the config flow only, when the API will be back and I can test all the component, or should I make a draft PR first ? Then a second one to add the battery sensors (new platform). Maybe new ones also to add iCloud calendar events and other sensors ... So I'm closing this PR. |
|
New PR is opened 😉 |
Breaking Change:
The iCloud component leaves the device_tracker component to be a all in one component (device_tracker + sensor)
From:
To:
It also adds some services :
SERVICE_ICLOUD_PLAY_SOUND = 'play_sound'
SERVICE_ICLOUD_DISPLAY_MESSAGE = 'display_message'
SERVICE_ICLOUD_LOST_DEVICE = 'lost_device'
SERVICE_ICLOUD_UPDATE = 'update'
SERVICE_ICLOUD_RESET = 'reset'
And rename some :
'icloud_lost_device' --> 'lost_device'
'icloud_update' --> 'update'
'icloud_reset' --> 'reset'
Description:
Hi everyone!
I would like to created sensors entity for all Apple devices link to an iCloud account, as I already did it, but using the template platform, and I saw a lot of people doing this.
I am new at Python development and even more in HomeAssistant dev, so don't hesitate to comment.
All reviewers and reviews are welcome 😉 !
Done:
Remaining work:
Delete CONF_MAX_INTERVAL if first optional work not madeOptional work:
Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#<home-assistant.io PR number goes here>
NOT YET
Example entry for
configuration.yaml(if applicable):Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
requirementsin the manifest (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.If the code does not interact with devices: