|
24 | 24 | ) |
25 | 25 | from pyvesync.models.purifier_models import ( |
26 | 26 | PurifierCoreDetailsResult, |
27 | | - PurifierV2DetailsResult, |
| 27 | + PurifierVitalDetailsResult, |
| 28 | + PurifierSproutResult, |
| 29 | + InnerPurifierBaseResult, |
28 | 30 | PurifierV2EventTiming, |
29 | 31 | PurifierV2TimerActionItems, |
30 | 32 | PurifierV2TimerPayloadData, |
@@ -457,8 +459,11 @@ def __init__( |
457 | 459 | """Initialize the VeSync Base API V2 Air Purifier Class.""" |
458 | 460 | super().__init__(details, manager, feature_map) |
459 | 461 |
|
460 | | - def _set_state(self, details: PurifierV2DetailsResult) -> None: |
| 462 | + def _set_state(self, details: InnerPurifierBaseResult) -> None: |
461 | 463 | """Set Purifier state from details response.""" |
| 464 | + if not isinstance(details, PurifierVitalDetailsResult): |
| 465 | + _LOGGER.debug("Invalid details model passed to _set_state") |
| 466 | + return |
462 | 467 | self.state.connection_status = ConnectionStatus.ONLINE |
463 | 468 | self.state.device_status = DeviceStatus.from_int(details.powerSwitch) |
464 | 469 | self.state.mode = details.workMode |
@@ -515,7 +520,7 @@ async def get_details(self) -> None: |
515 | 520 | """Build API V2 Purifier details dictionary.""" |
516 | 521 | r_dict = await self.call_bypassv2_api('getPurifierStatus') |
517 | 522 | r_model = process_bypassv2_result( |
518 | | - self, _LOGGER, "get_details", r_dict, PurifierV2DetailsResult |
| 523 | + self, _LOGGER, "get_details", r_dict, PurifierVitalDetailsResult |
519 | 524 | ) |
520 | 525 | if r_model is None: |
521 | 526 | return |
@@ -747,6 +752,90 @@ async def set_mode(self, mode: str) -> bool: |
747 | 752 | return True |
748 | 753 |
|
749 | 754 |
|
| 755 | +class VeSyncAirSprout(VeSyncAirBaseV2): |
| 756 | + """Class for the Sprout Air Purifier. |
| 757 | +
|
| 758 | + Inherits from VeSyncAirBaseV2 class and overrides |
| 759 | + the _set_state method. |
| 760 | +
|
| 761 | + Args: |
| 762 | + details (dict): Dictionary of device details |
| 763 | + manager (VeSync): Instantiated VeSync object |
| 764 | + feature_map (PurifierMap): Device map template |
| 765 | +
|
| 766 | + Attributes: |
| 767 | + state (PurifierState): State of the device. |
| 768 | + last_response (ResponseInfo): Last response from API call. |
| 769 | + manager (VeSync): Manager object for API calls. |
| 770 | + device_name (str): Name of device. |
| 771 | + device_image (str): URL for device image. |
| 772 | + cid (str): Device ID. |
| 773 | + connection_type (str): Connection type of device. |
| 774 | + device_type (str): Type of device. |
| 775 | + type (str): Type of device. |
| 776 | + uuid (str): UUID of device, not always present. |
| 777 | + config_module (str): Configuration module of device. |
| 778 | + mac_id (str): MAC ID of device. |
| 779 | + current_firm_version (str): Current firmware version of device. |
| 780 | + device_region (str): Region of device. (US, EU, etc.) |
| 781 | + pid (str): Product ID of device, pulled by some devices on update. |
| 782 | + sub_device_no (int): Sub-device number of device. |
| 783 | + product_type (str): Product type of device. |
| 784 | + features (dict): Features of device. |
| 785 | + modes (list[str]): List of modes supported by the device. |
| 786 | + fan_levels (list[int]): List of fan levels supported by the device. |
| 787 | + nightlight_modes (list[str]): List of nightlight modes supported by the device. |
| 788 | + auto_preferences (list[str]): List of auto preferences supported by the device. |
| 789 | + """ |
| 790 | + |
| 791 | + def __init__( |
| 792 | + self, |
| 793 | + details: ResponseDeviceDetailsModel, |
| 794 | + manager: VeSync, |
| 795 | + feature_map: PurifierMap, |
| 796 | + ) -> None: |
| 797 | + """Initialize air purifier class.""" |
| 798 | + super().__init__(details, manager, feature_map) |
| 799 | + |
| 800 | + def _set_state(self, details: InnerPurifierBaseResult) -> None: |
| 801 | + """Set Purifier state from details response.""" |
| 802 | + if not isinstance(details, PurifierSproutResult): |
| 803 | + _LOGGER.debug("Invalid details model passed to _set_state") |
| 804 | + return |
| 805 | + self.state.connection_status = ConnectionStatus.ONLINE |
| 806 | + self.state.device_status = DeviceStatus.from_int(details.powerSwitch) |
| 807 | + self.state.mode = details.workMode |
| 808 | + if details.fanSpeedLevel == 255: # noqa: PLR2004 |
| 809 | + self.state.fan_level = 0 |
| 810 | + else: |
| 811 | + self.state.fan_level = details.fanSpeedLevel |
| 812 | + self.state.fan_set_level = details.manualSpeedLevel |
| 813 | + self.state.child_lock = bool(details.childLockSwitch) |
| 814 | + self.state.air_quality_level = details.AQLevel |
| 815 | + self.state.pm25 = details.PM25 |
| 816 | + self.state.pm1 = details.PM1 |
| 817 | + self.state.pm10 = details.PM10 |
| 818 | + self.state.aq_percent = details.AQI |
| 819 | + self.state.display_set_status = DeviceStatus.from_int(details.screenSwitch) |
| 820 | + self.state.display_status = DeviceStatus.from_int(details.screenState) |
| 821 | + auto_pref = details.autoPreference |
| 822 | + if auto_pref is not None: |
| 823 | + self.state.auto_preference_type = auto_pref.autoPreferenceType |
| 824 | + self.state.auto_room_size = auto_pref.roomSize |
| 825 | + self.state.humidity = details.humidity |
| 826 | + self.state.temperature = int((details.temperature or 0) / 10) |
| 827 | + self.state.pm1 = details.PM1 |
| 828 | + self.state.pm10 = details.PM10 |
| 829 | + self.state.pm25 = details.PM25 |
| 830 | + self.state.voc = details.VOC |
| 831 | + self.state.co2 = details.CO2 |
| 832 | + if details.nightlight is not None: |
| 833 | + self.state.nightlight_status = DeviceStatus.from_int( |
| 834 | + details.nightlight.nightLightSwitch |
| 835 | + ) |
| 836 | + self.state.nightlight_brightness = details.nightlight.brightness |
| 837 | + |
| 838 | + |
750 | 839 | class VeSyncAir131(BypassV1Mixin, VeSyncPurifier): |
751 | 840 | """Levoit Air Purifier Class. |
752 | 841 |
|
|
0 commit comments