
    8i !                        S r SSKrSSKrSSKJrJrJrJrJr  SSK	J
r
JrJr  SSKrSSKJrJrJrJrJr  SSKJr  SSKJr  SSKJr  SS	KJrJr  SS
KJ r J!r!J"r"  SSK#J$r$J%r%  SSK&J'r'  \RP                  " \)5      r*Sr+Sr,Sr-Sr.Sr/\R`                  " \+5      \Rb                  \R`                  " \,5      \Rb                  0r2\R`                  " \-5      \Rb                  0r3Sr4Sr5\4\5/r6Sr7\Rp                  \Rr                  -  \Rt                  -  \Rv                  -  \Rx                  -  r=S\S\S\SS4S jr> " S S\%\5      r? " S S\?5      r@ " S S \?5      rA " S! S"\?5      rBg)#zFan platform for dyson.    N)AnyCallableListMappingOptional)DysonPureCoolDysonPureCoolLinkMessageType)DIRECTION_FORWARDDIRECTION_REVERSEFanEntityFeature	FanEntityNotValidPresetModeError)ConfigEntry)	CONF_NAME)HomeAssistant)config_validationentity_platform)int_states_in_rangepercentage_to_ranged_valueranged_value_to_percentage   )DOMAINDysonEntity)DATA_DEVICES	angle_low
angle_hightimer	set_angle	set_timerAutoNormal)r   
   hassconfig_entryasync_add_entitiesreturnc                    #    U R                   [           [           UR                     nUR                   [           n[        U[        5      (       a  [        X45      nO,[        U[        5      (       a  [        X45      nO[        X45      nU" U/5        [        R                  R                  5       nUR                  [        [         S5        [        U[        5      (       a  UR                  ["        [$        S5        gg7f)z%Set up Dyson fan from a config entry.r    r   N)datar   r   entry_idr   
isinstancer	   DysonPureCoolLinkEntityr   DysonPureCoolEntityDysonPurifierHumidifyCoolEntityr   current_platformgetasync_register_entity_serviceSERVICE_SET_TIMERSET_TIMER_SCHEMASERVICE_SET_ANGLESET_ANGLE_SCHEMA)r$   r%   r&   devicenameentityplatforms          ,/config/custom_components/dyson_local/fan.pyasync_setup_entryr;   @   s      YYv|,\-B-BCFY'D&+,,(6	FM	*	*$V20>x //335H**+[ &-((../	
 )s   C<C>c                   v   \ rS rSrSrSr\R                  r\	S\
4S j5       r\	SS j5       r\	S\4S j5       r\	S\\   4S	 j5       rS
\SS4S jr\	S\\   4S j5       r\	S\\   4S j5       rS\SS4S jr\	S 5       r\	S\4S j5       r  SS
\\   S\\   SS4S jjrSS jrS\
SS4S jrS\SS4S jrSrg)DysonFanEntityX   zDyson fan entity base class.Fr'   c                 .    U R                   R                  $ )zReturn if the fan is on.)_deviceis_onselfs    r:   rA   DysonFanEntity.is_on_   s     ||!!!    Nc                     g)z9Return None for compatibility with pre-preset_mode state.N rB   s    r:   speedDysonFanEntity.speedd   s     rE   c                      [        [        5      $ )z<Return the number of different speeds the fan can be set to.)r   SPEED_RANGErB   s    r:   speed_countDysonFanEntity.speed_counti   s     #;//rE   c                     U R                   R                  b  U R                   R                  (       a  gU R                   R                  (       d  g[	        [
        [        U R                   R                  5      5      $ )z$Return the current speed percentage.Nr   )r@   rH   	auto_moderA   r   rK   intrB   s    r:   
percentageDysonFanEntity.percentagen   sO     <<%)?)?||!!)+s4<<;M;M7NOOrE   rQ   c                     US:X  a  U R                   R                  5         g[        R                  " [	        [
        U5      5      nU R                   R                  U5        U R                   R                  5         g)z$Set the speed percentage of the fan.r   N)r@   turn_offmathceilr   rK   	set_speeddisable_auto_mode)rC   rQ   dyson_speeds      r:   set_percentageDysonFanEntity.set_percentagew   sT    ?LL!!#ii :;
 ST{+&&(rE   c                     [         $ )z"Return the preset modes supported.)SUPPORTED_PRESET_MODESrB   s    r:   preset_modesDysonFanEntity.preset_modes   s
     &%rE   c                 P    U R                   R                  (       a  [        $ [        $ )z(Return the current selected preset mode.)r@   rO   PRESET_MODE_AUTOPRESET_MODE_NORMALrB   s    r:   preset_modeDysonFanEntity.preset_mode   s     <<!!##%%rE   rc   c                     U[         :X  a  U R                  R                  5         gU[        :X  a  U R                  R	                  5         g[        SU 35      e)zConfigure the preset mode.zInvalid preset mode: N)ra   r@   enable_auto_moderb   rX   r   )rC   rc   s     r:   set_preset_modeDysonFanEntity.set_preset_mode   sG    **LL))+..LL**,),A+*OPPrE   c                 .    U R                   R                  $ )zReturn the oscillation state.)r@   oscillationrB   s    r:   oscillatingDysonFanEntity.oscillating   s     ||'''rE   c                     [         $ zFlag supported features.)COMMON_FEATURESrB   s    r:   supported_features!DysonFanEntity.supported_features   s
     rE   c                     [         R                  SU R                  U5        U(       a  U R                  U5        U(       a  U R	                  U5        U R
                  R                  5         g)zTurn on the fan.z!Turn on fan %s with percentage %sN)_LOGGERdebugr7   rg   rZ   r@   turn_on)rC   rQ   rc   kwargss       r:   ru   DysonFanEntity.turn_on   sK     	9499jQ  -
+rE   c                 v    [         R                  SU R                  5        U R                  R	                  5       $ )zTurn off the fan.zTurn off fan %s)rs   rt   r7   r@   rT   )rC   rv   s     r:   rT   DysonFanEntity.turn_off   s(    '3||$$&&rE   rk   c                     [         R                  SXR                  5        U(       a  U R                  R	                  5         gU R                  R                  5         g)zTurn on/of oscillation.z!Turn oscillation %s for device %sN)rs   rt   r7   r@   enable_oscillationdisable_oscillation)rC   rk   s     r:   	oscillateDysonFanEntity.oscillate   s8    9;		RLL++-LL,,.rE   r   c                 |    US:X  a  U R                   R                  5         gU R                   R                  U5        g)zSet sleep timer.r   N)r@   disable_sleep_timerset_sleep_timer)rC   r   s     r:   r    DysonFanEntity.set_timer   s+    A:LL,,.LL((/rE   rG   )r'   N)NN)__name__
__module____qualname____firstlineno____doc__+_enable_turn_on_off_backwards_compatibilityr
   STATE_MESSAGE_TYPEpropertyboolrA   rH   rP   rL   r   rQ   rZ   r   strr^   rc   rg   rk   rp   ru   rT   r}   r    __static_attributes__rG   rE   r:   r=   r=   X   sr   &27/%%M"t " "   0S 0 0 PHSM P P) ) ) &d3i & & &Xc] & &Q3 Q4 Q ( ( C   %)%)SM c]
 
'
/T /d /0s 0t 0rE   r=   c                       \ rS rSrSrSrg)r,      zDyson Pure Cool Link entity.rG   N)r   r   r   r   r   r   rG   rE   r:   r,   r,      s    &rE   r,   c                       \ rS rSrSr\S\4S j5       r\S\4S j5       r	S\SS4S jr
\S\4S	 j5       r\S\4S
 j5       r\S\\\4   4S j5       rS\S\SS4S jrSrg)r-      zDyson Pure Cool entity.r'   c                 0    [         [        R                  -  $ rn   ro   r   	DIRECTIONrB   s    r:   rp   &DysonPureCoolEntity.supported_features        !1!;!;;;rE   c                 P    U R                   R                  (       a  [        $ [        $ z%Return the current airflow direction.r@   front_airflowr   r   rB   s    r:   current_direction%DysonPureCoolEntity.current_direction        <<%%$$$$rE   	directionNc                     U[         :X  a  U R                  R                  5         gU[        :X  a  U R                  R	                  5         g[        SU 35      ez Configure the airflow direction.zInvalid direction Nr   r@   enable_front_airflowr   disable_front_airflow
ValueErrorrC   r   s     r:   set_direction!DysonPureCoolEntity.set_direction   G    ))LL--/++LL..01)=>>rE   c                 .    U R                   R                  $ )zReturn oscillation angle low.)r@   oscillation_angle_lowrB   s    r:   r   DysonPureCoolEntity.angle_low   s     ||111rE   c                 .    U R                   R                  $ )zReturn oscillation angle high.)r@   oscillation_angle_highrB   s    r:   r   DysonPureCoolEntity.angle_high   s     ||222rE   c                 F    [         U R                  [        U R                  0$ )z%Return fan-specific state attributes.)ATTR_ANGLE_LOWr   ATTR_ANGLE_HIGHr   rB   s    r:   extra_state_attributes*DysonPureCoolEntity.extra_state_attributes   s      DNNT__
 	
rE   r   r   c                 ~    [         R                  SUUU R                  5        U R                  R	                  X5        g)zSet oscillation angle.z*set low %s and high angle %s for device %sN)rs   rt   r7   r@   r{   )rC   r   r   s      r:   r   DysonPureCoolEntity.set_angle   s2    8II		
 	''	>rE   rG   )r   r   r   r   r   r   rP   rp   r   r   r   r   r   r   r   r   r   r   rG   rE   r:   r-   r-      s    !<C < < %3 % %?s ?t ? 23 2 2 3C 3 3 
S(9 
 
?3 ?C ?D ?rE   r-   c                   Z    \ rS rSrSr\S\4S j5       r\S\4S j5       r	S\SS4S jr
S	rg)
r.      z Dyson Pure Humidify+Cool entity.r'   c                 0    [         [        R                  -  $ rn   r   rB   s    r:   rp   2DysonPurifierHumidifyCoolEntity.supported_features  r   rE   c                 P    U R                   R                  (       a  [        $ [        $ r   r   rB   s    r:   r   1DysonPurifierHumidifyCoolEntity.current_direction  r   rE   r   Nc                     U[         :X  a  U R                  R                  5         gU[        :X  a  U R                  R	                  5         g[        SU 35      er   r   r   s     r:   r   -DysonPurifierHumidifyCoolEntity.set_direction  r   rE   rG   )r   r   r   r   r   r   rP   rp   r   r   r   r   rG   rE   r:   r.   r.      sL    *<C < < %3 % %?s ?t ?rE   r.   )Cr   loggingrU   typingr   r   r   r   r   libdysonr   r	   r
   
voluptuousvolhomeassistant.components.fanr   r   r   r   r   homeassistant.config_entriesr   homeassistant.constr   homeassistant.corer   homeassistant.helpersr   cvr   homeassistant.util.percentager   r   r    r   r   constr   	getLoggerr   rs   r   r   
ATTR_TIMERr4   r2   Requiredpositive_intr5   r3   ra   rb   r]   rK   	OSCILLATE	SET_SPEEDPRESET_MODETURN_ONTURN_OFFro   r;   r=   r,   r-   r.   rG   rE   r:   <module>r      s      9 9 B B   5 ) , J  " 


H
%
   LL "//LL!2??  LLboo    *,>?    !""#  	  


'2
HP
	
0j0[) j0Z'n '3?. 3?l?n ?rE   