Coordinator
The SunRiserCoordinator is the central hub of the integration. It owns the HTTP session, maintains the device config cache, and drives all polling.
Polling strategy
The coordinator uses a staggered round-robin to avoid overwhelming the WizFi360 Wi-Fi module:
tick 0: GET /state
tick 1: GET /state
tick 2: GET /state
tick 3: GET /state
tick 4: GET /weather ← then repeats from tick 0
...
every N ticks: one tick is replaced by POST / (re-read PWM config)
/weather is fetched only every 5th tick (~2.5 min at 30 s default) because the firmware writes the response to the SD card on each request, making it more expensive than a plain /state read.
One HTTP request per poll tick. The force_close=True TCP connector ensures the ESP8266 always sees a fresh single-use connection.
Init sequence
Before normal polling starts, four init ticks run sequentially:
| Tick | Request | Purpose |
|---|---|---|
| 0 | POST / |
Fetch base config (name, model, pwm_count, …) |
| 1 | GET /state |
Discover sensor ROMs, seed PWM values |
| 2 | POST / (one chunk per tick) |
Fetch per-channel PWM config and sensor metadata — chunks are drained one per tick to avoid back-to-back TCP connections during startup |
| 3 | GET /weather |
Fetch initial weather state so entities can be created |
Platform setup is deferred until all init ticks complete (including all chunk ticks for step 2).
Scheduled reboot
If scheduled_reboot is enabled in options (default: on), the coordinator registers a daily async_track_time_change listener at the configured reboot_time (default 04:00). At that time it calls async_reboot() silently. The listener is cancelled in async_close() and re-registered on options reload.
Failure handling
Connectivity failures are graced for 3 consecutive misses (_FAILURE_GRACE = 3). On the 3th failure a repair issue is raised in HA. Recovery automatically deletes the issue.
Reference
coordinator
Classes
SunRiserCoordinator
Bases: DataUpdateCoordinator[dict[str, Any]]
Coordinator that polls /state and holds device config.
Source code in custom_components/sunriser/coordinator.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 | |
Attributes
init_complete
property
True once all four init ticks have completed.
Functions
async_close()
async
Close the dedicated HTTP session, if one was created.
Source code in custom_components/sunriser/coordinator.py
142 143 144 145 146 147 148 | |
async_get_config(keys)
async
POST / — read config values, chunking by msgpack body size.
The WizFi360 delivers incoming TCP data via AT+IPD events. When the request body exceeds the module's buffer (~500–600 bytes this is a best guess) the payload is split across two AT+IPD events and the MCU firmware misparses the second chunk as additional msgpack array elements, causing '!!! element N is not msgpack str' errors and eventual watchdog resets. Keeping each msgpack body at or below _MAX_CONFIG_REQUEST_BODY_BYTES stays safely inside one AT+IPD delivery.
Source code in custom_components/sunriser/coordinator.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
async_set_config(params)
async
PUT / — write config key/value pairs.
The device requires save_version (set to factory_version) on every write so it can track the config lineage. See sunriser_network.js line 120.
Source code in custom_components/sunriser/coordinator.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
async_get_state()
async
GET /state — returns PWM values, sensor readings, uptime, etc.
Source code in custom_components/sunriser/coordinator.py
269 270 271 272 273 274 275 276 277 278 279 280 | |
async_get_weather()
async
GET /weather — returns per-channel weather simulation state.
The response is a msgpack stream whose first object is a list with one entry per PWM channel. Each entry is either None (no weather program assigned) or a dict with keys such as weather_program_id, clouds_state, cloudticks, clouds_next_state_tick, rainfront_start, rainfront_length, rainmins, rain_next_tick, moon_state, moon_next_state_tick.
Source code in custom_components/sunriser/coordinator.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
async_set_service_mode(enabled)
async
PUT /state — enable or disable maintenance mode.
When enabled the device stores the current timestamp in service_mode and freezes all PWM channels (except those with pwm#X#nomaint = true). When disabled it stores 0.
Source code in custom_components/sunriser/coordinator.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
async_set_timewarp(enabled)
async
PUT /state — activate or deactivate time-lapse (timewarp) mode.
When active the device runs the day/week planner at ~1800× speed. Weather simulation is suspended while time-lapse is active. Device expects integer 1/0 — msgpack boolean causes a 500.
Source code in custom_components/sunriser/coordinator.py
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | |
async_set_dst_auto_track(enabled)
async
Enable or disable automatic DST tracking.
User-initiated: fires a PUT / immediately to sync summertime so the device is correct the moment the switch is turned on. Poll-detected transitions are handled via _dst_sync_pending (replaces one tick).
Source code in custom_components/sunriser/coordinator.py
339 340 341 342 343 344 345 346 347 348 349 350 351 | |
async_set_pwms(pwm_values)
async
PUT /state — set PWM channels immediately.
Values are 0–1000. Note: if a program is running, it will resume control after ~1 minute. Use async_set_config with dayplanner keys for persistent changes.
Source code in custom_components/sunriser/coordinator.py
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | |
async_check_ok()
async
GET /ok — returns True if device responds with 'OK'.
Source code in custom_components/sunriser/coordinator.py
396 397 398 399 400 401 402 403 404 405 406 407 | |
async_reboot()
async
GET /reboot — initiate a device reboot.
Source code in custom_components/sunriser/coordinator.py
409 410 411 412 413 414 415 416 417 | |
async_get_factory_backup()
async
GET /factorybackup — download the factory default configuration as msgpack bytes.
Source code in custom_components/sunriser/coordinator.py
419 420 421 422 423 424 425 426 427 428 | |
async_get_firmware()
async
GET /firmware.mp — download firmware info as msgpack bytes.
Source code in custom_components/sunriser/coordinator.py
430 431 432 433 434 435 436 437 438 439 | |
async_get_bootload()
async
GET /bootload.mp — download bootloader info as msgpack bytes.
Source code in custom_components/sunriser/coordinator.py
441 442 443 444 445 446 447 448 449 450 | |
async_factory_reset()
async
DELETE / — reset all device configuration to factory defaults.
Source code in custom_components/sunriser/coordinator.py
452 453 454 455 456 457 458 459 460 | |
async_get_backup()
async
GET /backup — download complete device configuration as msgpack bytes.
Source code in custom_components/sunriser/coordinator.py
462 463 464 465 466 467 468 469 470 471 | |
async_restore(data)
async
PUT /restore — restore device configuration from msgpack backup bytes.
Unlike PUT /, this triggers a deeper device restart after applying config.
Source code in custom_components/sunriser/coordinator.py
473 474 475 476 477 478 479 480 481 482 483 484 485 486 | |
async_get_errors()
async
GET /errors — retrieve the device error log.
Source code in custom_components/sunriser/coordinator.py
488 489 490 491 492 493 494 495 496 497 | |
async_get_log()
async
GET /log — retrieve the device diagnostic log.
Source code in custom_components/sunriser/coordinator.py
499 500 501 502 503 504 505 506 507 508 | |
async_get_dayplanner(pwm)
async
Read the dayplanner schedule for a PWM channel from the config cache.
Returns a list of markers in the form [{"time": "HH:MM", "percent": N}, ...], sorted by time. Returns an empty list if no schedule is set.
Source code in custom_components/sunriser/coordinator.py
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 | |
async_get_weekplanner(pwm)
async
Read the weekplanner program assignment for a PWM channel.
Returns a dict mapping day names to program IDs. Day order matches the device: sunday(0)..saturday(6), default(7). 'default' is the fallback program used on days with no explicit assignment.
Source code in custom_components/sunriser/coordinator.py
542 543 544 545 546 547 548 549 550 551 552 553 554 | |
async_set_weekplanner(pwm, schedule)
async
Write the weekplanner program assignment for a PWM channel.
Accepts a dict with day names (sunday..saturday + default) mapped to program IDs. Missing days default to 0 (no program).
Source code in custom_components/sunriser/coordinator.py
556 557 558 559 560 561 562 563 | |
async_set_dayplanner(pwm, markers)
async
Write the dayplanner schedule for a PWM channel.
Each marker must have "time" (HH:MM) and "percent" (0–100). The flat array sent to the device is [daymin, percent, daymin, percent, ...].
Source code in custom_components/sunriser/coordinator.py
565 566 567 568 569 570 571 572 573 574 575 576 577 578 | |
async_load_device_config()
async
No-op — all config is loaded lazily by the poll loop.
Steps 0-3 of the init state machine each make exactly one HTTP request so the WizFi360 module has a full poll interval to tear down the TCP session before the next connection arrives.
Source code in custom_components/sunriser/coordinator.py
594 595 596 597 598 599 600 | |
pwm_manager(pwm_num)
Return the manager integer for a PWM channel (0–3).
Source code in custom_components/sunriser/coordinator.py
919 920 921 | |
pwm_value(pwm_num)
Current PWM value (0–1000) from latest state.
Source code in custom_components/sunriser/coordinator.py
926 927 928 929 930 | |
sensor_unit(rom)
0 = raw, 1 = celsius.
Source code in custom_components/sunriser/coordinator.py
940 941 942 | |
sensor_value(rom)
Decoded sensor reading, or None if unavailable.
Source code in custom_components/sunriser/coordinator.py
947 948 949 950 951 952 953 954 955 956 | |
DayplannerMarker
Bases: TypedDict
Source code in custom_components/sunriser/coordinator.py
43 44 45 | |